#include <reg52.h>
#define uint unsigned int #define uchar unsigned char
sbit E=P2^7; sbit RW=P2^6; sbit RS=P2^5; sbit k1=P1^7; sbit k2=P1^3;
unsigned long count; uint n, ajcs, yc=0; void delay(uchar z) { uchar x, y;
for (x = 110; x > 0; x--) { for (y = z; y > 0; y--); } }
void writecom(uchar com) //液晶的写指令 { RS=0; E=0; P0=com; delay(5); E=1; delay(5); E=0; }
void writedate(uchar date) //液晶的写数据 { RS=1; E=0; P0=date; delay(5); E=1; delay(5); E=0; }
void xianshi(uchar dz, unsigned long dx) //显示数字变化 { uint shiwan, wan, qian, bai, shi, ge;
shiwan=dx/100000; wan=dx/10000%10; qian=dx/1000%10; bai=dx/100%10; shi=dx/10%10; ge=dx%10;
writecom(0x80+dz); writedate(0x30+shiwan); writedate(0x30+wan); writedate(0x30+qian); writedate(0x30+bai); writedate(0x30+shi); writedate(0x30+ge); } void inti1() //液晶的初始化 { RW=0;
writecom(0x38); writecom(0x0c); writecom(0x06); writecom(0x01); writecom(0x80); }
void inti2() //中断的初始化 { EA=1; TMOD=0x51; TH0=0x4C; TL0=0x28; TH1=0; TL1=0; ET0=1; TR0=1; TR1=1; }
void inti3() { T2CON = 0x34; TH2 = 0xFF; TL2 = 0xDC; RCAP2H = 0xFF; RCAP2L = 0xDC; SCON = 0x50; TR2 = 1; TI=1; }
void fs(uchar x) { while(TI == 0); SBUF = x+0x30; TI = 0; }
void chuankou(unsigned long count) { uint shiwan, wan, qian, bai, shi, ge; k1=0; shiwan=count/100000; wan=count/10000%10; qian=count/1000%10; bai=count/100%10; shi=count/10%10; ge=count%10; if (k2 == 0) { delay(5); if(k2==0) { ajcs++; while(!k2); if (ajcs==1) { ajcs=0; fs(shiwan); fs(wan); fs(qian); fs(bai); fs(shi); fs(ge); while(TI == 0); SBUF = 'H'; TI = 0; while(TI == 0); SBUF = 'Z'; TI = 0; while(TI == 0); SBUF = ' '; TI = 0; } } } }
void timer0() interrupt 1 { n++; TH0=0x4C; TL0=0x28; if (TF1==1) { yc=yc+1; TF1=0; } if(n==20) { n=0; EA=0; count=TH1*256+TL1+yc*65536; yc=0; TH1=0; TL1=0; EA=1; } }
void main() {
inti1(); inti2(); inti3();
while(1) { chuankou(count); xianshi(2,count); } }
|