数码管显示!一天计时器,图片以后补!
不知道为什么数码管比较暗!(段少时比较亮)
刚才数码管的位老是乱串!
一查!是单片机的P2.1脚夹不紧!
[hid]
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar tcount,s,min,hour;
uchar code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
uchar disbuf[]={0,0,0,0,0,0,0,0};
uchar code place[]={0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00};
void main()
{ uchar i,k;
TMOD=0X01;
ET0=1;
EA=1;
TR0=1;
tcount=0;s=0;
min=0;hour=0;
while(1)
{
if(!TF0)
{
disbuf[1]=dispcode[s/10];
disbuf[0]=dispcode[s%10];
disbuf[2]=dispcode[10];
disbuf[4]=dispcode[min/10];
disbuf[3]=dispcode[min%10];
disbuf[5]=dispcode[10];
disbuf[7]=dispcode[hour/10];
disbuf[6]=dispcode[hour%10];}
for(i=0;i<20;i++)
{
for(k=0;k<8;k++)
{ P2=place[k];
P0=disbuf[k];
P0=0x00;
}
}}
}
void time1() interrupt 3
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TF0=0;
tcount++;
if(tcount==20)
{ tcount=0;
s++;
if(s==60)
{ s=0;
min++;
if(min==60)
{ min=0;
hour++;
if(hour==24)
hour=0;
}
}
}
}
数码管.rar!