各位大佬,我是个业余爱好者,基础差,,请教大家了,,
我想让1206上显示,时间(小时:分种,秒),不知道哪里错了,1206显示秒的地方,不是一秒一变化,同时进入一秒
的IF中不见leds变化,1206,显示的部分全删了,进入一秒的IF leds是有变化的,,一个个加的测试,也像一到1206写
命令处和1206写数据的地方,, leds一秒一变化,就不正常了,,(1206显示秒的地方,不是一秒一变化,)
谢谢谢谢
单片机源程序如下:
#include <reg52.h>
unsigned char ms;
//unsigned char ml;
sbit sm=P2^6; //RS 数据/命令选择。H/L.
sbit dx=P2^5; // R/W读写选择。H/L.
sbit eo=P2^7; // 使能
sbit leds=P2^0;
sbit ledf=P2^1;
sbit ledh=P2^2;
unsigned char t;
unsigned char code yihang[]="BeiJingShiJian";
unsigned char code erhang[]="0123456789";
/* 开定时器T0.定时5MS RST15F204 */
void InitTimer0()
{
TMOD = 0x01; //设定定时器0工作方式(16位定时器 )
TH0 = 0xEC; //
TL0 = 0x78; //
EA = 1; // 开总中断
ET0 = 1; // 开定时器0中断
TR0 = 1; // 启动定时器0
}
void Lcd1602_Delay1ms(unsigned int c) //误差 0us
{
unsigned char a,b;
for (; c>0; c--)
{
for (b=199;b>0;b--)
{
for(a=1;a>0;a--);
}
}
}
/*写命令比如光标显示与不显示,需不需要移屏,在液晶什么位置显示 */
void xieml (unsigned char ml)
{
eo=0;
dx=0; // R/W读写选择。H/L..
sm=0; //RS 数据/命令选择。H/L.
P0=ml;
Lcd1602_Delay1ms(2);
eo=1;
Lcd1602_Delay1ms(2);
eo=0;
}
/*写数据比如在液晶显示什么容 */
void xiesj(unsigned char sj)
{
eo=0;
dx=0; // R/W读写选择。H/L.
sm=1; //RS 数据/命令选择。H/L.
P0=sj;
Lcd1602_Delay1ms(2);
eo=1;
Lcd1602_Delay1ms(2);
eo=0;
}
/*1206初始化 */
void chushiha()
{
xieml(0X38);
xieml(0X0c);
// xieml(0X06);
xieml(0X01);
}
/*主函数,写入固定时间,驱动某个继电器 */
void main()
{
unsigned char n,s,f,h,sh,sg,fh,fg,hh,hg;
InitTimer0();
chushiha();
while(1)
{
if(ms==200)
{
ms=0; s=s+1; leds=~leds; //为了检测观察程序,加了一秒leds亮灭一次。
}
if(s==59)
{
s=0; f=f+1;ledf=~ledf; //为了检测观察程序,加了一分leds亮灭一次。
}
if(f==59)
{
f=0; h=h+1; ledh=~ledh;
}
if(h==11)
{
h=0;
}
sg=s%10; sh=s/10; // sg秒的个位数,sh秒十位数。
fg=f%10; fh=f/10; // fg分的个位数,fh分十位数。
hg=h%10; hh=h/10; // hg时的个位数,hh时十位数。
xieml(0X80+0X01);
for(n=0;n<14;n++)
{
xiesj(yihang[n]); //1206第一行显示BeiJingShiJian。
}
xieml(0X80+0X44);
xiesj(erhang[hh]); //1206第二行显示时间时的十位数。
xieml(0X80+0X45);
xiesj(erhang[hg]); //1206第二行显示时间时的个位数。
xieml(0X80+0X46);
xiesj(':');
xieml(0X80+0X47);
xiesj(erhang[fh]); //1206第二行显示时间分的十位数。
xieml(0X80+0X48);
xiesj(erhang[fg]); //1206第二行显示时间分的个位数。
xieml(0X80+0X49);
xiesj(',');
xieml(0X80+0X4A);
xiesj(erhang[sh]); //1206第二行显示时间秒的十位数。
xieml(0X80+0X4B);
xiesj(erhang[sg]); //1206第二行显示时间秒的个位数。
}
}
void T0_time() interrupt 1
{
TH0 = 0xEC; //
TL0 = 0x78;
ms++;
// if(ms==200){ms=0;led=~led;}
}
|