單片機+1602液晶數(shù)字時鐘程序
頭文件STC12C5A.H下載:http://www.51hei.com/mcu/2564.html
程序:
首先是主程序:
#include
#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.51hei.com/mcu/2965.html
這是另一個頭文件 自行保存即可
#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
評論