论坛首问!!!求助大神!!!
本人使用16x16点阵操作,使其显示汉字“普”,接下来我将会发段完整的程序,这两段完整的程序区别只在于主函数有无while(1)循环,我发现两个程序结果一样。
但是,本人认为第二段程序由于没有while(1)循环,结果应该是在LED显示屏上只有“普”字闪一下,而非一直亮着灯,求解!!!
程序一:
#include<reg51.h>
#include <intrins.h>
void delay(int i)
{
while(i--);
}
sbit SRCLK=P3^6;
sbit RCLK=P3^5;
sbit SER=P3^4;
unsigned char ledwei[]={
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned char code ledduan1[]={
0x40,0x44,0x54,0x64,0x45,0x7E,0x44,0x44,0x44,0x7E,0x45,0x64,0x54,0x44,0x40,0x00,
0x00,0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00,0x00,};
void Hc595SendByte(char dat1,char dat2,char dat3,char dat4)
{
int i;
for(i=0;i<8;++i)
{
SER=dat1>>7;
dat1=dat1<<1;
SRCLK=0;
_nop_();
_nop_();
SRCLK=1;
}
for(i=0;i<8;++i)
{
SER=dat2>>7;
dat2=dat2<<1;
SRCLK=0;
_nop_();
_nop_();
SRCLK=1;
}
for(i=0;i<8;++i)
{
SER=dat3>>7;
dat3=dat3<<1;
SRCLK=0;
_nop_();
_nop_();
SRCLK=1;
}
for(i=0;i<8;++i)
{
SER=dat4>>7;
dat4=dat4<<1;
SRCLK=0;
_nop_();
_nop_();
SRCLK=1;
}
RCLK=0;
_nop_();
_nop_();
RCLK=1;
}
void main()
{
int i;
while(1)
{
for(i=0;i<16;i++)
{
Hc595SendByte(~ledwei[i+16],~ledwei[i],ledduan1[i+16],ledduan1[i]);
delay(10);
}
}
}
程序二:
#include<reg51.h>
#include <intrins.h>
void delay(int i)
{
while(i--);
}
sbit SRCLK=P3^6;
sbit RCLK=P3^5;
sbit SER=P3^4;
unsigned char ledwei[]={
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned char code ledduan1[]={
0x40,0x44,0x54,0x64,0x45,0x7E,0x44,0x44,0x44,0x7E,0x45,0x64,0x54,0x44,0x40,0x00,
0x00,0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00,0x00,};
void Hc595SendByte(char dat1,char dat2,char dat3,char dat4)
{
int i;
for(i=0;i<8;++i)
{
SER=dat1>>7;
dat1=dat1<<1;
SRCLK=0;
_nop_();
_nop_();
SRCLK=1;
}
for(i=0;i<8;++i)
{
SER=dat2>>7;
dat2=dat2<<1;
SRCLK=0;
_nop_();
_nop_();
SRCLK=1;
}
for(i=0;i<8;++i)
{
SER=dat3>>7;
dat3=dat3<<1;
SRCLK=0;
_nop_();
_nop_();
SRCLK=1;
}
for(i=0;i<8;++i)
{
SER=dat4>>7;
dat4=dat4<<1;
SRCLK=0;
_nop_();
_nop_();
SRCLK=1;
}
RCLK=0;
_nop_();
_nop_();
RCLK=1;
}
void main()
{
int i;
for(i=0;i<16;i++)
{
Hc595SendByte(~ledwei[i+16],~ledwei[i],ledduan1[i+16],ledduan1[i]);
delay(10);
}
}
一周热门 更多>