你们好,我想问一下你们。我这个程序为什么会出现问题?
本人比较笨,拜托各位大神教教我!实在是很难受,弄了这么久。
———————————————————————————————————————————————————————————————————————
当按下“setplace”按键之后,TR0=0,定时器0会停止,单片机停止对DS1302的寄存器进行读取 同时,place++(place的值改变指定不一样的位置)
按道理,跟随place值的改变,光标会在指定的位置闪烁才对啊 现在出现的问题是光标怎么会一直跑飞呢?
———————————————————————————————————————————————————————————————————————
相关的子函数如下:
void ds_readtime(void) //ds1302读取寄存器子函数
{
miao=BCD_Decimal(ds_read(0x81));
fen=BCD_Decimal(ds_read(0x83));
shi=BCD_Decimal(ds_read(0x85));
ri=BCD_Decimal(ds_read(0x87));
yue=BCD_Decimal(ds_read(0x89));
xingqi=BCD_Decimal(ds_read(0x8b));
nian=BCD_Decimal(ds_read(0x8d));
}
———————————————————————————————————————————————————————————————————————
void InitTimer(void) //定时器的初始化函数
{
TMOD = 0x11;
EA = 1;
TH0=0;
TL0=0;
ET0 = 1;
TR0 = 1;
TH1 = 0x3C;
TL1 = 0x0B0;
ET1 = 1;
TR1 = 1;
}
void Timer0Interrupt(void) interrupt 1 //定时器0功能子函数
{
ds_readtime(); //读取ds1302各个寄存器的值到hour,minute,second,week,day,month,year中
}
———————————————————————————————————————————————————————————————————————
void keyscan() //键盘扫描函数
{
if(setplace==0) //这个按键按下会改变光标的位置
{
delay10ms();
if(setplace==0)
{
place++;
while(setplace==0);
if(pingmu==0) //我设置了4个屏幕,现在这个屏幕是显示时钟的
{
if(place==8) place=0;
if(place==1)
{
temp2=(miao)/10*16+(miao)%10;
ds_write(0x8e,0x00);
ds_write(0x80,0x00|temp2); //miao数据写入DS1302
ds_write(0x8e,0x80);
TR0=0;
lcd_writecom(0x83);
lcd_writecom(0x0f);
}
if(place==2)
{
TR0=0;
lcd_writecom(0x86);
lcd_writecom(0x0f);
}
if(place==3)
{
TR0=0;
lcd_writecom(0x89);
lcd_writecom(0x0f);
}
if(place==4)
{
TR0=0;
lcd_writecom(0x8f);
lcd_writecom(0x0f);
}
if(place==5)
{
TR0=0;
lcd_writecom(0xc8);
lcd_writecom(0x0f);
}
if(place==6)
{
TR0=0;
lcd_writecom(0xcb);
lcd_writecom(0x0f);
}
if(place==7)
{
TR0=0;
lcd_writecom(0xce);
lcd_writecom(0x0f);
}
if(place==0)
{
lcd_writecom(0x0c); //按动到第8次,设置光标不闪烁
TR0=1; //打开定时器0
temp2=(miao)/10*16+(miao)%10;
ds_write(0x8e,0x00);
ds_write(0x80,0x00|temp2);//miao数据写入DS1302
ds_write(0x8e,0x80);
}
}
}
}
}
|