專(zhuān)注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

單片機(jī)+1602液晶數(shù)字時(shí)鐘程序(成功版)

作者:huqin   來(lái)源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2014年03月15日   【字體:

先來(lái)看制作成功的圖:


本程序由好幾個(gè)頭文件組成,都在下面,你可以復(fù)制代碼并保存為獨(dú)立的文件
頭文件STC12C5A.H下載: http://www.torrancerestoration.com/mcu/2564.html

程序:
首先是主程序:
#include<STC12C5A.H>
#include "STDIO.h"
#include "LCD1602.h"
#include "interrupt.h"

void main()
{
 LCD_init();
 interrupts_init();    
 LCD_disp_cher(0, 1,"784729514 ");
 while(1)
  {
   sprintf(dsa,"%d:%d:%d ",hour,minute,sec);
   LCD_disp_cher(0,2,dsa);
  }
}

下面是lcd1602.H頭文件: http://www.torrancerestoration.com/mcu/2965.html

這是另一個(gè)頭文件 自行保存即可
#ifndef _interrupt_H_
#define _interrupt_H_
#define uint unsigned int
#define uchar unsigned char
uint sec,subtle,minute,hour;
uchar dsa[16];
void interrupts_init()
{
 EA=1; 
 ET0=1;
   TR0=1;  
 TMOD=0x1; 
 TH0=(65536-50000)/255;
 TL0=(65536-50000)%255;
}
void ghjfgf() interrupt 1
{
 TH0=(65536-50000)/255; 
TL0=(65536-50000)%255;
 subtle++;
 if(subtle==20)
  {
   subtle=0;
   sec++;
  }
 if(sec==60)
  {
   sec=0;
   minute++;
  }
 if(minute==60)
  {
   minute=0;
   hour++;
  }
 if(hour==24) hour=0;
}
#endif

關(guān)閉窗口

相關(guān)文章