#include <reg52.h>
sbit ADD0 = P2^0;
sbit ADD1 = P2^1;
sbit ADD2 = P2^2;
typedef unsigned char uint8;
typedef unsigned int uint16;
typedef unsigned long uint32;
uint8 code ledchar[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uint8 shuchar[6]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
uint8 i;
uint16 ci;
uint32 shu;
void main()
{
EA=1;
TMOD=0x01;
TH0=0xFC;
TL0=0x67;
ET0=1;
TR0=1;
while(1)
{
if(ci>=1000)
{
ci=0;
shu++;
shuchar[0]=ledchar[shu%10];
shuchar[1]=ledchar[shu/10%10];
shuchar[2]=ledchar[shu/100%10];
shuchar[3]=ledchar[shu/1000%10];
shuchar[4]=ledchar[shu/10000%10];
shuchar[5]=ledchar[shu/10000%10];
}
}
}
void Interrupt
timer0() interrupt 1
{
TH0=0xFC;
TL0=0x67;
ci++;
P0=0xFF;
switch(i)
{
case 0:ADD0=1;ADD1=1;ADD2=1;i++;P0=shuchar[0];break;
case 1:ADD0=0;ADD1=1;ADD2=1;i++;P0=shuchar[1];break;
case 2:ADD0=1;ADD1=0;ADD2=1;i++;P0=shuchar[2];break;
case 3:ADD0=0;ADD1=0;ADD2=1;i++;P0=shuchar[3];break;
case 4:ADD0=1;ADD1=1;ADD2=0;i++;P0=shuchar[4];break;
case 5:ADD0=0;ADD1=1;ADD2=0;i=0;P0=shuchar[5];break;
default:break;
}
}
sbit ADD0 = P2^0;
sbit ADD1 = P2^1;
sbit ADD2 = P2^2;
typedef unsigned char uint8;
typedef unsigned int uint16;
typedef unsigned long uint32;
uint8 code ledchar[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uint8 shuchar[6]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
uint8 i;
uint16 ci;
uint32 shu;
void main()
{
char i;
uint8 buf[6];//中间转换缓冲区
EA=1;
TMOD=0x01;
TH0=0xFC;
TL0=0x67;
ET0=1;
TR0=1;
while(1)
{
if(ci>=1000)
{
ci=0;
shu++;
buf[0] = sec%10;
buf[1] = sec/10%10;
buf[2] = sec/100%10;
buf[3] = sec/1000%10;
buf[4] = sec/10000%10;
buf[5] = sec/100000%10;
for(i=5;i>=1;i--) //从最高为开始,遇到0不显示,遇到非0退出循环
{
if(buf[i] == 0)
shuchar[i] = 0xFF;
else
break;
}
//将剩余的有效数字位如实转换
for( ;i>=0;i--) /for()起始未对j操作,j即保持上个循环结束时的值
{
shuchar[i] =ledchar[buf[i]];
}
}
}
void InterruptTimer0() interrupt 1
{
TH0=0xFC;
TL0=0x67;
ci++;
P0=0xFF;
switch(i)
{
case 0:ADD0=1;ADD1=1;ADD2=1;i++;P0=shuchar[0];break;
case 1:ADD0=0;ADD1=1;ADD2=1;i++;P0=shuchar[1];break;
case 2:ADD0=1;ADD1=0;ADD2=1;i++;P0=shuchar[2];break;
case 3:ADD0=0;ADD1=0;ADD2=1;i++;P0=shuchar[3];break;
case 4:ADD0=1;ADD1=1;ADD2=0;i++;P0=shuchar[4];break;
case 5:ADD0=0;ADD1=1;ADD2=0;i=0;P0=shuchar[5];break;
default:break;
}
还是蛮有用的
还是蛮有用的
这是错误的
一周热门 更多>