|
- //贴一个
- #include
- #include
- #define uchar unsigned char
- #define uint unsigned int
- uchar code welcom[16]={" Welcome! "};
- uchar idata timer[16]={" 22:55:33 "};
- uchar timecount;
-
- sbit RS=P1^0;
- sbit RW=P1^1;
- sbit EN=P1^2;
-
- bit timeflag;
- void delay(uint time)
- {
- uint x,y;
- for(x=time;x>0;x--)
- for(y=112;y>0;y--);
- }
- bit LcdBusy(void)
- {
- bit result;
- EN = 0;
- RS = 0;
- RW = 1;
- EN = 1;
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- result=(bit)(P2&0x80);
- _nop_();
- EN=0;
- return result;
- }
- void WriteData(uchar Data)
- {
- while(LcdBusy());
- RS = 1;
- RW = 0;
- EN = 0;;
- P2 = Data;
- _nop_();
- EN = 1;
- _nop_();
- EN = 0;
- }
- void WriteCom(uchar Com,bit test)
- {
- if(test)
- while(LcdBusy());
- RS = 0;
- RW = 0;
- EN = 0;
- P2 = Com;
- _nop_();
- EN = 1;
- _nop_();
- EN = 0;
- }
- void IntiLcd(void)
- {
- delay(15);
- WriteCom(0x38,0);
- delay(5);
- WriteCom(0x38,0);
- delay(5);
- WriteCom(0x38,0);
- WriteCom(0x38,1);
- WriteCom(0x08,1);
- /*WriteCom(0x01,1);*/
- WriteCom(0x06,1);
- WriteCom(0x0c,1);
- }
- void LcdXY(uchar y,uchar x)
- {
- uchar addr;
- addr=(y-1)*0x40+(x-1);
- WriteCom(addr|0x80,1);
- }
- void DisString(uchar *Matric)
- {
- uchar i;
- for(i=0;i<16;i++)
- WriteData(Matric[i]);
- }
- void timer0(void)interrupt 1
- {
- TH0 = (65536-50000)/256;
- TL0 = (65536-50000)%256;
- if(++timecount>=20)
- {
- timecount =0;
- timeflag =1;
- }
- }
- void Watch(void)
- {
- if(timeflag)
- {
- timeflag=0;
- if(++timer[11]>=':')
- {
- timer[11]='0';
- if(++timer[10]>='6')
- {
- timer[10]='0';
- if(++timer[8]>=':')
- {
- timer[8]='0';
- if(++timer[7]>='6')
- {
- timer[7]='0';
- if(++timer[5]>=':')
- {
- timer[5]='0';
- timer[4]++;
- }
- if((timer[5]>='4')&&(timer[4]>='2'))
- {
- timer[5]='0';
- timer[4]='0';
- }
- }
- }
- }
- }
- LcdXY(2,1);
- DisString(timer);
- }
- }
- void Inti(void)
- {
- TMOD = 0x01;
- TH0 = (65536-50000)/256;
- TL0 = (65536-50000)%256;
- EA = 1;
- ET0 = 1;
-
- timecount =0;
- timeflag =0;
- }
- int main()
- {
- Inti();
- IntiLcd();
- LcdXY(1,1);
- DisString(welcom);
- LcdXY(2,1);
- DisString(timer);
- TR0=1;
- while(1)
- {
- Watch();
- }
- return 0;
- }
复制代码 |
|