|
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar num=0,AN=0,e;
char fen=0,miao=0;
sbit rs=P2^0;
sbit rw=P2^1;
sbit E=P2^2;
sbit beef=P1^5;
sbit key1=P3^2; //选择时间
sbit key2=P3^3; //增加时间
sbit key3=P3^4; //减少时间
void delay_50us(uchar i)
{
uchar j;
for( ;i>0;i--)
for(j=100;j>0;j--);
}
void write_com(uchar com)
{
rs=0;
rw=0;
E=0;
P0=com;
delay_50us(10);
E=1;
delay_50us(20);
E=0;
}
void write_data(uchar dat)
{
rs=1;
rw=0;
E=0;
P0=dat;
delay_50us(10);
E=1;
delay_50us(20);
E=0;
}
void write_shu(uchar add,uchar date)
{
uchar ge,shi;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_data(0x30+shi);
write_data(0x30+ge);
}
void init(void)
{
delay_50us(300);
write_com(0x38);
delay_50us(10);
write_com(0x38);
delay_50us(10);
write_com(0x38);
write_com(0x38);
write_com(0x08);
write_com(0x01);
write_com(0x06);
write_com(0x0c);
write_com(0x80);
write_com(0x80+0x46);
write_data(':');
delay_50us(10);
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void key_scan()
{
if(key1==0)
delay_50us(100);
if(key1==0)
{
TR0=0;
AN++;
while(!key1);
}
if(AN==1)
{
write_com(0x80+0x40+8);
write_com(0x0f);
if(key2==0)
delay_50us(100);
if(key2==0)
{
while(!key2);
miao++;
if(miao==60)
{
beef=~beef;
delay_50us(10);
miao=0;
fen++;
if(fen==60)
fen=0;
write_shu(4,fen);
}
write_shu(7,miao);
}
}
if(AN==2)
{
write_com(0x80+0x40+5);
write_com(0x0f);
if(key2==0)
delay_50us(100);
if(key2==0)
{
while(!key2);
fen++;
if(fen==60)
fen=0;
write_shu(4,fen);
}
}
if(AN==1)
{
write_com(0x80+0x40+8);
write_com(0x0f);
if(key3==0)
delay_50us(100);
if(key3==0)
{
while(!key3);
miao--;
if(miao==60)
{
beef=~beef;
delay_50us(10);
miao=0;
fen++;
if(fen==60)
fen=0;
write_shu(4,fen);
}
write_shu(7,miao);
}
}
if(AN==2)
{
write_com(0x80+0x40+5);
write_com(0x0f);
if(key3==0)
delay_50us(100);
if(key3==0)
{
while(!key3);
fen--;
if(fen==60)
fen=0;
write_shu(4,fen);
}
}
if(AN==3)
{
TR0=1;
AN=0;
write_com(0x0c);
详细程序请下载压缩包
|
|