- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit LCD_RS=P2^6;
- sbit LCD_RW=P2^5;
- sbit LCD_E=P2^7;
- sbit k2=P3^0;
- long int count,count1;
- char mil,sec,min,mil1,sec1,min1;
- unsigned char code table[ ]=" miaobiao ";
- unsigned char code table1[ ]=" 00:00:0 ";
- void delay(uint z)
- {
- uchar j,k;
- for(j=z;j>0;j--)
- for(k=256;k>0;k--);
- }
- void write_com(uchar com)
- {
- LCD_RS=0;
- LCD_E=0;
- LCD_RW=0;
- LCD_DATAPINS=com;
- delay(5);
- LCD_E=1;
- delay(5);
- LCD_E=0;
- }
- void write_date(uchar date)
- {
- LCD_RS=1;
- LCD_E=0;
- LCD_RW=0;
- LCD_DATAPINS=date;
- delay(5);
- LCD_E=1;
- delay(5);
- LCD_E=0;
- }
- void init()
- {
- uchar num;
- LCD_E=0;
- write_com(0x38);
- write_com(0x0c);
- write_com(0x06);
- write_com(0x01);
- write_com(0x80);
- for(num=0;num<20;num++)
- {
- write_date(table[num]);
- delay(5);
- }
- write_com(0x80+0x40);
- for(num=0;num<12;num++)
- {
- write_date(table1[num]);
- delay(5);
- }
- TMOD=0x01;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- EA=1;
- ET0=1;
- EX0=1;
- TR0=0;
- }
- void write_min(uchar add,uchar date)
- {
- uchar one,two;
- one=date/10;
- two=date%10;
- write_com(0x80+0x40+add);
- write_date(0x30+one);
- write_date(0x30+two);
- }
- void write_sec(uchar add,uchar date)
- {
- uchar three,four;
- three=date/10;
- four=date%10;
- write_com(0x80+0x40+add);
- write_date(0x30+three);
- write_date(0x30+four);
- }
- void write_mil(uchar add,uchar date)
- {
- uchar five;
- five=date%10;
- write_com(0x80+0x40+add);
- write_date(0x30+five);
- }
- void zjs()
- {
- if(count==2)
- {
- delay(5);
- count=0;
- mil++;
- if(mil==10)
- {
- delay(5);
- mil=0;
- sec++;
- if(sec==60)
- {
- delay(5);
- sec=0;
- min++;
- if(min==60)
- {
- delay(5);
- min=0;
- mil=0;
- }
- }
- }
- write_min(4,min);
- write_sec(7,sec);
- write_mil(10,mil);
- }
- }
- void main()
- {
- init();
- while(1)
- {
- zjs();
- }
- }
- void int0() interrupt 0
- {
- delay(10);
- TR0=~TR0;
- }
- void timer0() interrupt 1
- {
- count++;
- }
復制代碼
|