|
单片机用手里闲置的STC89C52RC.并在开发板上调试成功。
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
sbit d1=P1^0;//定义d1
sbit d2=P1^7;//定义d1
sbit key1=P3^2;//按键定义
sbit key2=P3^3;
sbit key3=P3^4;
sbit key4=P3^5;
sbit LED1=P2^3;
sbit LED2=P2^2;
sbit LED3=P2^1;
sbit LED4=P2^0;
uchar temp,aa,miaos,miaog,qian,bai,shi,ge,fen,sh,bb,mh;
void display(uchar qian,uchar bai,uchar shi,
uchar ge);
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init();
void main()
{
init();//初始化子程序
mh=1;
while(1)
{
if(key1==0)
{
delay(200);
while(key1==0);
fen++;
if(fen==59)
{
fen=0;
}
}
if(key2==0)
{
delay(200);
while(key2==0);
if(fen!=0)
{
fen--;
}
if(fen==0)
{
fen=59;
}
}
if(key3==0)
{
delay(200);
while(key3==0);
sh++;
if(sh==23)
{
sh=0;
}
}
if(key4==0)
{
delay(200);
while(key4==0);
if(sh!=0)
{
sh--;
}
if(sh==0)
{
sh=23;
}
}
if(aa==20)
{
bb++;
aa=0;
miaog=bb%10;
miaos=bb/10%6;
mh=~mh;
}
if(bb==60)
{
fen++;
bb=0;
}
ge=fen%10;
shi=fen/10%6;
if(fen==60)
{ sh++;
fen=0;
fen=0;
}
bai=sh%10;
qian=sh/10;
if(bai==10)
bai=0;
if(qian==2)
{
if(bai==4)
{
qian=0;
bai=0;
}
}
if(sh==24)
{
sh=0;
}
display(qian,bai,shi,ge);
}
}
void display(uchar qian,uchar bai,uchar shi,
uchar ge)
{
LED1=1;
P0=table[qian];
LED1=0;
delay(1);
LED1=1;
LED2=1;
P0=table[bai];
LED2=0;
delay(1);
LED2=1;
LED2=1;
if(mh==1)
{
P0=0x7F;
}
else P0=0xFF;
LED2=0;
delay(3);
LED2=1;
LED3=1;
P0=table[shi];
LED3=0;
delay(1);
LED3=1;
LED4=1;
P0=table[ge];
LED4=0;
delay(1);
LED4=1;
}
void init()
{
d1=1;
d2=1;
fen=0;
sh=0;
temp=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
}
|
评分
-
查看全部评分
|