单片机二进制时钟
玛丽莲梦兔
539次浏览
2021年01月17日 16:25
最佳经验
本文由作者推荐
随从获取-这是四点零八分的北京
单片机二进制时钟
[
源码
&
电路
]
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit
SET_H=P0^6;
sbit
SET_M=P0^5;
sbit
SET_S=P1^6;
uchar code DSY_CODE[]=
//
用于显示时钟的编码
{
0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9, 0xa,0xb,0xc,
0xd,0xe,0xf,0x10,0x11,0x12,0x13,0 x14,0x15,0x16,0x17,
0x18,0x19,0x1a,0x1b,0x1c,0 x1d,0x1e,0x1f,0x20,0x21,
0x22,0x23,0x24,0x25,0 x26,0x27,0x28,0x29,0x2a,0x2b,
0x2c,0x2d,0x2e,0 x2f,0x30,0x31,0x32,0x33,0x34,0x35,
0x36,0x37,0x38,0x39,0x3a,0x3b
};
uint hour=0,min=0,sec=0,count=0;
void delay_ms(unsigned char i)
{
unsigned char j;
while(i--)
for(j=124;j>0;j--);
}
void Set_Interrupt_1()
{
if(SET_H==0)
{
delay_ms(100);
if(SET_H==0)
{
TR0=0;
if(hour<23)
hour++;
else
hour=0;
//delay_ms(50);
TR0=1;
P0=~DSY_CODE[hour];
P1=~DSY_CODE[min];
P2=~DSY_CODE[sec];
}
}
}
void Set_Interrupt_2()
{
if(SET_M==0)
{
delay_ms(100);
if(SET_M==0)
{
TR0=0;
TH0 = (65535-50000)/256;
TL0
= (65535-50000)%256;
if(min<59)
min++;
else
{
min=0;
hour++;
if(hour==24)
hour=0;
}