每小时1秒左右,菜鸟恳请大侠们指点指点。 下次用实时时钟芯片做个试试。
/*************************** PROJECT: LCD显示时钟 AUTHOR: lrl DATE: 2009-07-12 STATUS: COMPLETED **************************/ #include<reg52.h> #define uint unsigned int #define uchar unsigned char sbit led=P1^0; sbit du=P1^1; sbit we=P1^2; sbit rs=P2^7; sbit rw=P2^6; sbit en=P2^5; code uchar time[]=" : : "; code uchar string[]="09-07-12 BY LRL"; code uchar table[]="0123456789";
uchar i,shi,fen,miao,shi_s,shi_g,fen_s,fen_g,miao_s,miao_g; void delay(uint z) { uint t1,y; for(t1=z;t1>0;t1--) for(y=110;y>0;y--); }
void wr_command(uchar a) { led=1; we=1; P0=0xff; led=0; we=0;
rs=0; en=1; P0=a; delay(1); en=0; }
void wr_data(uchar a) { led=1; we=1; P0=0xff; led=0; we=0;
rs=1; en=1; // delay(100);// 说明是高电平也是有效的,而不仅仅是高脉冲。 P0=a; // en=1; delay(1); en=0; }
void init() { rw=0; wr_command(0x38); wr_command(0x0c);
EA=1; TMOD=0X01; TH0=(65535-46080)/256; //50ms@11.0592MHZ, 46080=50*11.0592*1000/12 TL0=(65535-46080)%256; ET0=1; TR0=1; }
void main() { uchar i,j; init(); wr_command(0x80+0x04); for(j=0;j<8;j++) { wr_data(time[j]); delay(2); } wr_command(0x80+0x41); for(i=0;i<15;i++) { wr_data(string); delay(2); } while(1) { wr_command(0x80+0x04); wr_data(table[shi_s]); delay(2); wr_command(0x80+0x05); wr_data(table[shi_g]); delay(2); wr_command(0x80+0x07); wr_data(table[fen_s]); delay(2); wr_command(0x80+0x08); wr_data(table[fen_g]); delay(2); wr_command(0x80+0x0a); wr_data(table[miao_s]); delay(2); wr_command(0x80+0x0b); wr_data(table[miao_g]); delay(2); }
}
void timer0() interrupt 1 { TH0=(65535-46080)/256; TL0=(65535-46080)%256; i++; if(i==20) { i=0; miao++; if(miao==60) { miao=0; fen++; if(fen==60) { fen=0; shi++; if(shi==24) { shi=0; }; }; }; }
miao_s=miao/10; miao_g=miao%10; fen_s=fen/10; fen_g=fen%10; shi_s=shi/10; shi_g=shi%10; }
|