51单片机设计电子时钟。
发布网友
发布时间:2022-05-01 05:47
我来回答
共2个回答
热心网友
时间:2022-06-25 04:57
#include <reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit key1=P3^0;
sbit key2=P3^1;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar shi,fen,miao,num1 ,num2,num3,num4,num5,num6,num7;
void delayms (uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void miaodisplay (uchar num6,uchar num5)
{
P2=0x00;
P2=0x80;
P1=table[num6];
delayms(5);
P2=0x00;
P2=0x40;
P1=table[num5];
delayms(5);
}
void fendisplay(uchar num4,uchar num3)
{
P2=0x00;
P2=0x10;
P1=table[num4];
delayms(5);
P2=0x00;
P2=0x08;
P1=table[num3];
delayms(5);
}
void shidisplay(uchar num2,uchar num1)
{
P2=0x00;
P2=0x02;
P1=table[num2];
delayms(5);
P2=0x00;
P2=0x01;
P1=table[num1];
delayms(5);
}
void main ()
{
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
EA=1;
ET0=1;
TR0=1;
shi=0;
fen=0;
miao=0;
num7=0;
while (1)
{
num1=shi/10;
num2=shi%10;
num3=fen/10;
num4=fen%10;
num5=miao/10;
num6=miao%10;
miaodisplay(num6,num5);
P2=0x00;
P2=0x20;
P1=0xbf;
delayms(5);
fendisplay(num4,num3);
P2=0x00;
P2=0x04;
P1=0xbf;
delayms(5);
shidisplay(num2,num1);
}
}
void T0_time () interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
num7++;
if(num7==20)
{
num7=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
fen=0;
miao=0;
}
}
}
}
}
热心网友
时间:2022-06-25 04:58
汇编程序可能跑飞了没反回追问我是C语言编写的