#include#defineucharunsignedchar#defineuintunsignedintsbitdula=P2^1;//ÉêÃ÷U1Ëø´æÆ÷µÄËø´æ¶...
#include
#define uchar unsigned char
#define uint unsigned int
sbit dula = P2^1; //ÉêÃ÷U1Ëø´æÆ÷µÄËø´æ¶Ë
sbit wela = P2^2; //ÉêÃ÷U2Ëø´æÆ÷µÄËø´æ¶Ë
uchar code table1[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x40}; //¶¨Òå¶ÎÏÔʾÊý×é0-9
uchar code table2[]={0x20,0x10}; //¶¨ÒåλÊý×éλÏÔʾ1£¬2
uchar num1,num2;
void init(); //µ÷Óóõʼ»¯º¯Êý
void delay(uint); //µ÷ÓÃÑÓʱº¯Êý
void main()
{
num1=0;
while(1)
{
init(); //³õʼ»¯ÊýÂë¹Ü
wela = 1;
P0 = table2[1]; //Ñ¡ÖÐ2λ
wela = 0;
dula = 1;
P0 = table1[num1]; //ÏÔʾ0-9
num1++;
delay(500);
dula = 0;
while(num1>9)
{
wela = 1;
P0 = table2[0]; //Ñ¡ÖÐһλ
wela=0;
dula = 1;
P0 = table1[num1];
dula = 0;
num1++;
delay(500);
dula = 0;
}
}
}
void init()
{
wela=1; //´ò¿ªU2Ëø´æÆ÷¶Ë
P0 = 0; //¹Ø±ÕËùÓÐλ
wela = 0; //¹Ø±ÕU2Ëø´æÆ÷
dula = 1;
P0 = 0xff; //¹Ø±ÕÏÔʾ
dula=0;
}
void delay(uint z)
{
uint i,j;
for(i=z;i>0;i--)
for(j=110;j>0;j--);
}
展开