#include<reg52.h>
sbit ADDR0=P1^0;
sbit ADDR1=P1^1;
sbit ADDR2=P1^2;
sbit ADDR3=P1^3;
sbit ENLED=P1^4;
unsigned char code LedChar[17]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xff};
void delay_ms(unsigned char cnt)
{
unsigned char i;
unsigned char j;
while(cnt--)
{
for(i=0;i<=110;i++);
for(j=0;j<=110;j++);
}
}
void main()
{
unsigned char i,j;
ENLED=0;
while(1)
{
for(i=0;i<10;i++) //循环扫描,修改i可设置时长
{
ADDR0=0;ADDR1=0;ADDR2=0;ADDR3=0;P0=LedChar[17]; //消隐
ADDR0=0;ADDR1=0;ADDR2=0;ADDR3=1;P0=LedChar[j]; //显示数字
delay_ms(20); //动态扫描显示延时,不能修改
ADDR0=0;ADDR1=0;ADDR2=0;ADDR3=0;P0=LedChar[17]; //消隐
ADDR0=0;ADDR1=0;ADDR2=1;ADDR3=0;P0=LedChar[j]; //显示数字
delay_ms(20); //动态扫描显示延时,不能修改
}
if(j++==10) j=0; //数字指针累加
}
} |