本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
请教高手看看这个时钟程序哪边有错误,我检查不出来!(p0口直接接数码管段选;p2口接s8550的基极,低电平是s8550导通,驱动数码管;p3口接按钮;数码管用的共阳的。)
#include <reg52.h>
char cout0,cout1,k,i;
char miao=0;
char fen=0;
char shi=0;
char duanma[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x3f};
char weima[9]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
char huancun[8];
void delay(uchar i)
{
do
{
huancun[0]=miao%10;
huancun[1]=miao/10;
huancun[2]=10;
huancun[3]=fen%10;
huancun[4]=fen/10;
huancun[5]=10;
huancun[6]=shi%10;
huancun[7]=shi/10;
}while(i--);
}
void timer1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
if(++cout1==20)
{
cout1=0;
if(++miao==60)
{
miao=0;
if(++fen==60)
{
fen=0;
if(++shi==24)
shi=0;
}
}
}
}
void timer0() interrupt 1
{
if(++cout0==10)
{
cout0=0;
P2=weima[i];
P0=duanma[huancun[i]];
i++;
if(i==8) i=0;
}
}
char scankey()
{
char k;
P3=0x00;
P3=0xff;
k=P3&0xff;
if(k==0xff) return 0xff;
else if(k==0xfe) return 1;
else if(k==0xfd) return 2;
else if(k==0xfb) return 3;
else if(k==0xf7) return 4;
else if(k==0xef) return 5;
else if(k==0xdf) return 6;
else if(k==0xbf) return 7;
else if(k==0x7f) return 8;
}
songjian()
{
char j;
while(1)
{
j=scankey();
if(j==scankey()&&j==0xff) break;
}
}
void main()
{
TMOD=0x12;
TH0=256-250;
TL0=256-250;
TR0=1;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR1=1;
IE=0x8a;
while(1)
{
k=scankey();
delay(100);
if(k==scankey()&&k!=0xff)
{
songjian();
if(k==1)
{
TR1=0;
while(1)
{
k=scankey();
delay(100);
if(k==scankey()&&k!=0xff)
{
songjian();
if(k!=1)
{
switch(k)
{
case 3:miao++;
if(miao==60) miao=0;
break;
case 4:miao--;
if(miao==0xff) miao=59;
break;
case 5:fen++;
if(fen==60) fen=0;
break;
case 6:fen--;
if(fen==0xff) fen=59;
break;
case 7:shi++;
if(shi==24) shi=0;
break;
case 8:shi--;
if(shi==0xff) shi=23;
break;
}
}
if(k==2) {TR1=1;break;}
}
}
}
}
}
} |