大家看下這個程序,簡單的1602程序,不知道為什么小時位進不了位,只有分鐘,秒可以進位,大家幫幫忙。。我真的身心疲憊了
#include<reg52.h> #define uint unsigned int #define uchar unsigned char sbit wela=P2^7; sbit dula=P2^6; sbit lcden=P3^4; sbit lcdrs=P3^5; sbit lcdwr=P3^6; uchar table[]=" 2011-11-14 MON "; uchar table1[]=" 23:59:00 "; uchar count,miao,fen; uint shi; void delay(uint z) { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void write_com(com)//寫指令函數 { lcdrs=0; lcden=0; P0=com; delay(5); lcden=1; delay(5); lcden=0; } void write_dat(dat)//寫數據函數 { lcdrs=1; lcden=0; P0=dat; delay(5); lcden=1; delay(5); lcden=0; } void init() {uchar num; wela=0; dula=0; lcden=0; lcdwr=0; write_com(0x38); delay(1); write_com(0x0c); write_com(0x06); //write_com(0x01); write_com(0x80); for(num=0;num<16;num++) { write_dat(table[num]); delay(20); } write_com(0x80+0x40); for(num=0;num<12;num++) { write_dat(table1[num]); delay(20); } TMOD=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=1; miao=54; //shi=23; } void write_sfm(uchar add, uchar date) { uchar shi,ge; shi=date/10; ge=date%10; write_com(0x80+0x40+add); write_dat(0x30+shi); write_dat(0x30+ge); } void main() { init(); while(1) { if(count==20) { count=0; miao++; if(miao==60) { miao=0; fen++; if(fen==60) { fen=0; shi++; if(shi==24) { shi=0; } write_sfm(3,shi); } write_sfm(6,fen); } write_sfm(9,miao); }
} } void timer0() interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; count++;} |