本程序由好几个头文件组成,都在下面,你能够仿制代码并保存为独立的文件
头文件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