// file name:shu ma guan.c
// designer: PES_LiWeiJin
#include"reg51.h"
本文引用地址:http://m.butianyuan.cn/article/201611/320825.htm#define uchar unsigned char
#define uint unsigned int
uchar leddata[]={
0xC0,0xF9, 0xA4, 0xB0, 0x99, 0x92,
0x82, 0xF8, 0x80, 0x90,0x88
};
uchar ddshow[]={0x00,0x00,0x00,0x00};
uchar scan[]={0xfe,0xfd,0xfb,0xf7};
//delay for 1ms
void delay1ms(uint t)
{
uint i;
uchar j;
for(i=0;i for(j=0;j<120;j++);
}
//show leddata
void datashow()
{
ddshow[0]++;
delay1ms(100); //try to change the delay value...
if(ddshow[0]==10)
{
ddshow[0]=0;
ddshow[1]++;
if(ddshow[1]==6)
{
ddshow[1]=0;
ddshow[2]++;
if(ddshow[2]==10)
{
ddshow[2]=0;
ddshow[3]++;
if(ddshow[3]==6)
ddshow[3]=0;
ddshow[2]=0;
ddshow[1]=0;
ddshow[0]=0;
}
}
}
}
//main
void main()
{
uchar i;
while(1)
{
datashow();
for(i=0;i<4;i++)
{
P0=leddata[ddshow[i]];
P1=scan[i];
delay1ms(1); //try to change the delay value...
}
}
}
評(píng)論