8*8单色点阵,可以直接用。需要修改显示可以自己取模。
源码:
#include<reg51.h>
sbit SRCLK=P3^6;
sbit RCLK=P3^5;
sbit SER=P3^4;
unsigned char code TAB[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
unsigned char code han[4][8]=
{
0x30,0x78,0x7C,0x3E,0x7C,0x78,0x30,0x00,
0x00,0xff,0xd3,0xd3,0xff,0xd7,0x85,0xff,
0x22,0xfc,0x24,0x3e,0x38,0x28,0x28,0x38,
0x00,0x52,0x2c,0x3e,0x2a,0xfe,0x2e,0x3e,
};
void delay(unsigned int i)
{
unsigned int k,l;
for(k=0;k<i;k++)
{
for(l=0;l<5;l++);
}
}
void duan(unsigned char dat)
{
unsigned char a;
SRCLK=0;
RCLK=0;
for(a=0;a<8;a++)
{
SER=dat>>7;
dat<<=1;
SRCLK=1;
delay(3);
SRCLK=0;
}
RCLK=1;
delay(3);
RCLK=0;
}
void main()
{
unsigned char h,j;
unsigned int i;
while(1)
{
for(i=0;i<50;i++)
{
for(h=0;h<8;h++)
{
duan(0x00);
P0=TAB[h];
duan(han[j][h]);
delay(1);
}
}
j++;
if(j==4)
{
j=0;
}
}
}
供大家学习参考,多多指点。
|