AT89C51数字时钟keil代码
时间: 2023-12-04 10:41:01 浏览: 78
以下是AT89C51数字时钟的Keil代码示例:
```c
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
uchar hour, min, sec;
bit flag;
void delay(uint z)
{
uint x, y;
for (x = z; x > 0; x--)
for (y = 110; y > 0; y--);
}
void display()
{
uchar i;
for (i = 0; i < 8; i++)
{
P2 = 0xff;
P0 = table[hour / 10];
P2 = 0xfe;
delay(5);
P2 = 0xff;
P0 = table[hour % 10];
P2 = 0xfd;
delay(5);
P2 = 0xff;
P0 = table[min / 10];
P2 = 0xfb;
delay(5);
P2 = 0xff;
P0 = table[min % 10]; P2 = 0xf7;
delay(5);
if (flag == 0)
{
P2 = 0xff;
P0 = table[sec / 10];
P2 = 0xef;
delay(5);
P2 = 0xff;
P0 = table[sec % 10];
P2 = 0xdf;
delay(5);
}
else
{
P2 = 0xff;
P0 = 0x00;
P2 = 0xef;
delay(5);
P2 = 0xff;
P0 = 0x00;
P2 = 0xdf;
delay(5);
}
}
}
void init()
{
TMOD = 0x01;
TH0 = 0x4c;
TL0 = 0x00;
EA = 1;
ET0 = 1;
TR0 = 1;
}
void main()
{
init();
while (1)
{
display();
}
}
void timer0() interrupt 1
{
TH0 = 0x4c;
TL0 = 0x00;
sec++;
if (sec == 60)
{
sec = 0;
min++;
if (min == 60)
{
min = 0;
hour++;
if (hour == 24)
{
hour = 0;
}
}
}
flag = ~flag;
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)