注:本時鐘沒有涉及到時鐘芯片,也沒有液晶顯示器,只是用單片機的定時器簡單設計一個時鐘!!!
注:此設計非原創,度娘也能找到!!!
proteus仿真電路圖:
proteus仿真成功:
元件清單:
部分源代碼:
#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
code uchar d[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
uint second=0,minter=50,hour=11;
uint sshi,sge,mge,mshi,hshi,hge;
static char court=0;
sbit P21=P2^1;
sbit P22=P2^2;
sbit P23=P2^3;
sbit P24=P2^4;
sbit P25=P2^5;
sbit P26=P2^6;
sbit P27=P2^7;
sbit P20=P2^0;
void delay() //單個LED延時函數
{
uchar i;
for(i=0;i<15;i++);
}
void int1()interrupt 1 using 2 //定時中斷相應定50ms
{
TH0=0x3c; //注:此處是3c,不是4c,附件里是4c,改過來,否者時鐘走的慢!!!
TL0=0x00;
court++;
}
void main() //主函數
{
TMOD=0x01;
TH0=0x00;
TL0=0x00;
EA=1;
ET0=1;
TR0=1;
P1=0XFF;
for(;;)
{
sshi=second/10; //求分秒的個位
sge=second%10;
mshi=minter/10;
mge=minter%10;
hshi=hour/10;
hge=hour%10;
P0=d[sge]; //時分秒在LED的顯示
P27=1; //P0口數據輸出,P2口選通信號
delay();
剩余代碼見附件!
51時鐘.7z
(31.08 KB, 下載次數: 65)
2019-3-16 09:36 上傳
點擊文件名下載附件
|