帮我看下,哪里有问题,为何时钟不走。
#include
#include
#define delay4us() {_nop_();_nop_();_nop_();_nop_();}
#define uchar unsigned char
#define uint unsigned int
sbit lcd_rs = P2^4;//Pin4 ;
sbit lcd_rw = P2^5; //Pin5 ;
sbit lcd_en= P2^6;//Pin6
uchar code title_text[]={" current time "};
//uchar count_str[]=" " ;
uchar s=0,m=30,h=12, hour,min,sec;
uchar count=0;
uchar count_str[]=" 12:30:00 ";
void delay(uint ms)
{
uchar t;
while(ms--) for(t=0;t<120;t++);
}
//LCD忙检测
bit lcd_busy_check()
{
bit result;
lcd_rs=0;
lcd_rw=1;
lcd_en=1;
delay4us();
result=(bit)(P0&0x80);
lcd_en=0;
return result;
}
//写命令
void lcd_write_command(uchar cmd)
{
while(lcd_busy_check());
lcd_rs=0;
lcd_rw=0;
lcd_en=0;
_nop_();
_nop_();
P0=cmd;delay4us();
lcd_en=1;delay4us();
lcd_en=0;
}
//写数据
void lcd_write_data(uchar str)
{
while(lcd_busy_check());
lcd_rs=1;
lcd_rw=0;
lcd_en=0;
P0=str;delay4us();
lcd_en=1;
delay4us();
lcd_en=0;
}
//初始化
void lcd_initialise()
{
lcd_write_command(0x38);delay(5);
lcd_write_command(0x0c);delay(5);
lcd_write_command(0x06);delay(5);
lcd_write_command(0x01);delay(5);
}
//设置显示位置
void lcd_set_position(uchar pos)
{
lcd_write_command(pos|0x80);
}
void display_string(uchar *str,uchar lineno)
{
uchar k;
lcd_set_position(lineno);
for(k=0;k<16;k++)
lcd_write_data(str[k]);
}
//void display_hms(uchar hour,min,sec)
void main()
{
P0=P2=0XFF;
delay(10);
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
IE=0X82;
lcd_initialise();
display_string(title_text,0x00);
TR0=1;
P1=0XFF;
while(1)
{count_str[3]=' ';
count_str[4]=hour/10+'0';
count_str[5]=hour%10+'0';
count_str[7]=min/10+'0';
count_str[8]=min%10+'0';
count_str[10]=sec/10+'0';
count_str[11]=sec%10+'0';
while(1)
display_string(count_str,0x40);
delay(500);
delay(500);
}
}
void time_0()interrupt 1
{
uchar c=0,count=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(++c==20)
{
c=0;
if(++sec==60)
{
sec=0;
if(++min==60)
{
min=0;
if(++hour==24)
{
hour=0;sec=0;min=0;
}
}
}
}
}