標題:
電子時鐘仿真與單片機編程
[打印本頁]
作者:
zjzjzjz
時間:
2018-3-25 20:10
標題:
電子時鐘仿真與單片機編程
電子時鐘仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
0.png
(13.73 KB, 下載次數(shù): 63)
下載附件
2018-3-26 01:48 上傳
0.png
(46.31 KB, 下載次數(shù): 54)
下載附件
2018-3-26 01:48 上傳
單片機源程序如下:
//LED6CC_CLOCK
#include <AT89X52.H>
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
unsigned char dispbitcode[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
unsigned char dispbuf[6]={0,0,0,0,2,1};
unsigned char dispbitcnt;
unsigned char second;
unsigned char minite;
unsigned char hour;
unsigned int tcnt;
unsigned char mstcnt;
unsigned char i,j;
void delay()
{
unsigned char i,j;
for(i=5;i>0;i--)
for(j=248;j>0;j--);
}
void main(void)
{
TMOD=0x02;
TH0=0x06;
TL0=0x06;
TR0=1;
ET0=1;
EA=1;
hour=12;
while(1)
{
if(P0_0==0)
{
delay();
if(P0_0==0)
{
second++;
if(second==60)
{
second=0;
}
dispbuf[0]=second%10;
dispbuf[1]=second/10;
while(P0_0==0);
}
}
if(P0_1==0)
{
delay();
if(P0_1==0)
{
minite++;
if(minite==60)
{
minite=0;
}
dispbuf[2]=minite%10;
dispbuf[3]=minite/10;
while(P0_1==0);
}
}
if(P0_2==0)
{
delay();
if(P0_2==0)
{
hour++;
if(hour==24)
{
hour=0;
}
dispbuf[4]=hour%10;
dispbuf[5]=hour/10;
while(P0_2==0);
}
}
}
}
void t0(void) interrupt 1
{
mstcnt++;
if(mstcnt==6)
{
mstcnt=0;
P3=0xff; //關閉所有顯示
P3=dispbitcode[dispbitcnt];//
P1=dispcode[dispbuf[dispbitcnt]];//
dispbitcnt++;
if(dispbitcnt==6)
{
dispbitcnt=0;
}
}
tcnt++;
if(tcnt==4000)
{
tcnt=0;
second++;
if(second==60)
{
second=0;
minite++;
if(minite==60)
{
minite=0;
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
電子鐘.rar
(40.12 KB, 下載次數(shù): 10)
2018-3-25 20:39 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1