#2
小焦叔叔2020-02-15 21:00
|
#include "reg52.h"
#define ucher unsigned char
#define uint unsigned int
typedef unsigned char u8;
sbit LCD_RW=P2^5;
sbit LCD_RS=P2^6;
sbit LCD_E=P2^7;
sbit k1=P3^0;
sbit k2=P3^1;
sbit k3=P3^2;
sbit k4=P3^3;
ucher count,fen,miao,hao;
u8 disp[]="11 ";
ucher code disp1[]=" 00:00:0";
void delay(uint c)
{
uint a,b;
for (a=0; a<c; a++)
for (b=0; b<124; b++);
}
void lcdwrite_com(ucher com)
{
LCD_E=0;
LCD_RS=0;
LCD_RW=0;
LCD_DATAPINS=com;
delay(5);
LCD_E=1;
delay(5);
LCD_E=0;
}
void lcdwrite_date(ucher date)
{
LCD_E=0;
LCD_RS=1;
LCD_RW=0;
LCD_DATAPINS=date;
delay(5);
LCD_E=1;
delay(5);
LCD_E=0;
}
void init()
{
fen=00;
miao=00;
hao=00;
lcdwrite_com(0x38);
lcdwrite_com(0x38);
lcdwrite_com(0x38);
lcdwrite_com(0x0c);
lcdwrite_com(0x06);
lcdwrite_com(0x01);
{
ucher num;
lcdwrite_com(0x00+0x80);
for(num=0;num<16;num++)
{
lcdwrite_date(disp[num]);
}
lcdwrite_com(0x80+0x40);
for(num=0;num<11;num++)
{
lcdwrite_date(disp1[num]);
}
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
}
void lcdwrite_fmh1(ucher add,ucher date)
{
ucher h;
h=date%10;
lcdwrite_com(0x80+0x40+add);
lcdwrite_date(0x30+h);
}
void lcdwrite_fmh(ucher add,ucher date)
{
ucher s,g;
s=date/10;
g=date%10;
lcdwrite_com(0x80+0x40+add);
lcdwrite_date(0x30+s);
lcdwrite_date(0x30+g);
}
void main()
{
init();
while(1)
{
if(count==2)
{
count=0;
hao++;
if(hao==10)
{
hao=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
}
lcdwrite_fmh(4,fen);
}
lcdwrite_fmh(7,miao);
}
lcdwrite_fmh1(10,hao);
}
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
}