电子时钟显示电路
发布时间:2024-11-08
发布时间:2024-11-08
单片机程序设计
#include<reg51.h>
unsigned char duanxuan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40}; unsigned char weixuan[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char chushi[]={1,2,10,0,0,10,0,0};
sbit P0_0=P0^0;
sbit P0_1=P0^1;
sbit P0_2=P0^2;
unsigned char second,minite,hour;
unsigned char tcnt=0;
unsigned int k;
void delay05s()
{
for(second=0;second<60;second++)
for(minite=0;minite<60;minite++)
for(hour=0;hour<24;hour++);
}
void main()
{
unsigned char k=0,tcnt=0;
TMOD=0x02;
TH0=(256-250);
TL0=(256-250);
TR0=1;
EA=1;
hour=12;
while(1)
{
if(P0_0==0)
{
delay05s();
if(P0_0==0)
{
second++;
if(second==60)
{
second=0;
}
}
}
chushi[6]=second/10;
单片机程序设计
chushi[7]=second%10; }
while(1)
{
if(P0_1==0)
{
delay05s(); if(P0_1==0) {
minite++; if(minite==60) {
minite=0; }
}
}
chushi[3]=minite/10; chushi[4]=minite%10; }
while(1)
{
if(P0_2==0)
{
delay05s(); if(P0_2==0) {
hour++; if(hour==24) {
hour=0; }
}
}
chushi[0]=hour/10;
chushi[1]=hour%10; }
}
void zhong() interrupt 1 using 1 {
P3=0xff;
P3=weixuan[tcnt];
P1=duanxuan[chushi[tcnt]];
单片机程序设计
} tcnt++; if(tcnt==8) { tcnt=0; } k++; if(k==4000) { k=0; second++; if(second==60) { second=0; minite++; if(minite==60) { minite=0; hour++; if(hour==24) { hour=0; } } } } chushi[6]=second/10; chushi[7]=second%10; chushi[3]=minite/10; chushi[4]=minite%10; chushi[0]=hour/10; chushi[1]=hour%10;