漢字流水燈顯示,簡單的漢字就可以了。
我下面一段程序,我編譯下載后,單片機運行,8*8點陣是亂的。為什么?
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar C_cross[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar R_cross[10][8]={
{0x00,0x42,0x46,0x4a,0x52,0x62,0x42,0x00},//"Z"
{0x00,0x40,0x40,0x7e,0x40,0x40,0x00,0x00},//"T"
{0x7e,0x20,0x10,0x08,0x10,0x20,0x7e,0x00},//"M"
{0x00,0x42,0x42,0x7e,0x42,0x42,0x00,0x00},//"I"
{0x30,0x48,0x44,0x32,0x44,0x48,0x30,0x00},//"LOVE"
{0x00,0x80,0x40,0x3e,0x40,0x80,0x00,0x00}, //"Y"
{0x30,0x28,0x14,0x38,0x38,0x14,0x28,0x30},//"LOVE,LOVE"
{0x00,0x80,0x40,0x3e,0x40,0x80,0x00,0x00}, //"Y"
{0x00,0x20,0x20,0x1e,0x10,0x20,0x20,0x00}, //"R"
{0x00,0x7e,0x42,0x42,0x42,0x24,0x18,0x00} //"D"
};
uchar offset;
uchar n;
void Delayms(uchar mt)
{
uchar t;
for(mt;mt>0;mt--)
for(t=110;t>0;t--);
}
void main(void)
{
uchar i;
uchar *p;
n=0;
TMOD=0x01;
TH0=0xfc;
TL0=0x18;
ET0=1;
EA=1;
TR0=1;
p=&R_cross[0][0];
while(1)
{
for(i=0;i<8;i++)
{
Delayms(10000);
P0=*(p+offset);
P2=C_cross;
p++;
if(p>&R_cross[0][7])
p=&R_cross[0][0];
}
}
}
void timer0() interrupt 1 using 3
{
TF0=0;
TH0=0xfc;
TL0=0xe18;
if(n<200)
{
n++;
}
else
{
n=0;
offset+=1;
if(offset>72)
offset=0;
}
}
我后來找了單片機附贈的靜態顯示程序,這個可以調試成功,顯示一個心形
/*copyright 2007,ShangHai HaoTun Electronic Technology co.,Ltd
*
*This sample is used for 7-seg led dynamic display .
*
*write by Shifang 2007-4-23
*
*V1.1
*/
#include <reg52.h>
unsigned char const dofly[]={0x00,0x6C,0x92,0x82,0x44,0x28,0x10,0x00};// 心的形狀
unsigned char code seg[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};//分別對應相應的段亮
////////////////////////////////////////////////////////
void delay(unsigned int cnt)
{
while(--cnt);
}
///////////////////////////////////////////////////////
main()
{
unsigned char i;
while(1)
{
P0=dofly;//取顯示數據
P2=seg; //取段碼
delay(200); //掃描間隙延時
i++;
if(8==i)
i=0;
}
}
這二者間,我還是搞不懂,怎么由靜態轉為動態,求大神指導~
|