#include
#define uchar unsigned char #define uint unsigned int sbit RS=P2^0; sbit RW=P2^1; sbit E=P2^2; sbit key1=P2^3; sbit key2=P2^4; sbit key3=P2^5; void delay(void); void init(void);
void wc51r(uchar i); void wc51ddr(uchar i); void fbusy(void);
void LCD_xianshi(void); void delay_zs(uint z); void tiaoshi(void);
uchar hour,hour1,min,min1,sec,sec1,aa,bb,num1,num2,num3,flag; uchar year1,year2,year3,year4,month,month1,month2,day,day1,day2; unsigned int year;
uchar tab[]={0x30,0x31,0x32,0x33,0x34, 0x35,0x36,0x37,0x38,0x39};
void main() { init(); while(1) {
LCD_xianshi(); } }
void init() {
// key1=1;key2=1;key3=1;
num1=12;year=2010;month=11;day=15; // wc51r(0x01); wc51r(0x38); wc51r(0x0c); wc51r(0x06);
TMOD=0x01; //工作方式1
TH0=(65536-5000)/256; //定时器高位装初值 计数溢出一次为50ms TL0=(65536-5000)%256; //定时器低位装初值
EA=1; //CPU开中断 ET0=1; //允许T0中断 // ET1=1;
TR0=1; //启动T0工作 // TR1=1; }
void fbusy() {
RW=1;RS=0; E=1;
while(!P1&0x80); E=0; delay(); }
void wc51r(uchar j) {
fbusy();
E=0;RS=0;RW=0; E=1; P1=j; E=0; delay(); }
void wc51ddr(uchar j) {
fbusy();
E=0;RS=1;RW=0; E=1; P1=j; E=0; delay(); }
void delay() {
uchar i,j;
for(j=0;j<10;j++) for(i=0;i<10;i++); }
/*void delay_zs(uint z) {
uint x,y;
for(x=z;x>0;x--) for(y=110;y>0;y--); } */
void LCD_xianshi() {
year1=year/1000;year2=year/100%10;year3=year%100/10;year4=year%10; month1=month/10;month2=month%10;day1=day/10;day2=day%10; hour=num1/10; hour1=num1%10; min=num2/10; min1=num2%10; sec=num3/10; sec1=num3%10;
wc51r(0x84); //起始地址为第1行第1列,0x85为第1行第6列;0xc0为第2行第1列
wc51ddr(tab[hour]); //显示 1 wc51ddr(tab[hour1]); //显示 2 wc51ddr(0x3a); //显示 : wc51ddr(tab[min]); //显示 0 wc51ddr(tab[min1]); //显示 0 wc51ddr(0x3a); //显示 : wc51ddr(tab[sec]); wc51ddr(tab[sec1]); wc51r(0xc3);
wc51ddr(tab[year1]); wc51ddr(tab[year2]); wc51ddr(tab[year3]); wc51ddr(tab[year4]); wc51ddr('-');
wc51ddr(tab[month1]); wc51ddr(tab[month2]); wc51ddr('-');
wc51ddr(tab[day1]); wc51ddr(tab[day2]); }
/*void tiaoshi(void) {
while(key1) {
TR0=0; if(key2==0) {
LCD_xianshi; num3++;
if(num3==60) {
num3=0;num2++; } }
else if(key3==0)num2++; }
// while(key1);
// if(key1==0){ET0=1;TR0=1;flag=0;} } */
//************************定时器中断程序**************************// void timer0() interrupt 1 {
TH0=(65536-50000)/256; //重装计数初值 TL0=(65536-50000)%256; aa++;
if(aa==20) //计数20次后恰为20x50ms==1s { aa=0;
num3++; //秒 加1
if(num3==60) //秒 计数到60后清零 {
num3=0; num2++;
if(num2==60) {
num2=0; num1++;
if(num1==24) {
num1=0; day++;
if(month%2==0) {
if(day==31) {
day=0;month++; if(month==13)
{
month=0;year++; } } }
else if(month%2==1) {
if(day==32) {
day=0;month++; if(month==13) {
month=0;year++; } } } } } } } }
//************************定时器中断程序**************************// /*void timer1() interrupt 3 {
TH1=(65536-50000)/256; //重装计数初值 TL1=(65536-50000)%256; bb++;
if(bb%20==0) {
if(key1==0) {
ET0=0;TR0=0;flag=1; } } }*/
我可以帮你搞搞的