以下是我的按键控制液晶显示的程序,从实时时钟读取是个时间 在液晶上显示,用一个按键控制这10个时间按的显示,当第一次按下按键时,光标移到J上,并显示最近一次读到的程序,再次按下时 光标移到I上,显示其对应的时间,依次次类推,调试时,多次按下按键时液晶才会有显示,有时候又会连续跳好几次,如从D跳到A,大家帮我看看为什么会这样,各位有什么更好的实现方法,请大家帮我指点指点 谢谢 (为方便,调试时按4个时间写的)
sbit key1=P3^7;
sbit key2=P4^2;
uchar idata BUFFER1[]={"00-00-00"};
uchar idata BUFFER2[]={"00:00:00"};extern void Delay_m(unsigned int L_i);
extern void show_string(uchar *ch,uchar x,uchar y,uchar flag);//字符串显示程序
extern void Format_DateTime(uchar d,uchar *a); // 将读取的时间年月日时分秒转换成字符串
extern void clear();
uchar keyprocessor();
extern uchar xdata tim1[6],tim2[6],tim3[6],tim4[6],tim5[6],tim6[6],tim7[6],tim8[6],tim9[6],tim10[6];//读取的时间
uchar keyprocessor()
{
uchar keyin,keyins;
keyin=key1;
Delay_m(500);
keyins=key1;
if((keyin==0)&(keyins==0))
{
return 1;
}
}
void show_time()
{
//uchar idata BUFFER1[]={"00-00-00"}; //局部变量??全局变量???
//uchar idata BUFFER2[]={"00:00:00"};
uchar kest=0;
static uchar tnum=4;
kest=keyprocessor();
if(kest==1)
{
//switch(tnum)
//{
//case 1:
if(tnum==1)
{
show_string("A",6,0,1);
Format_DateTime(tim1[5],BUFFER1);
Format_DateTime(tim1[4],BUFFER1+3);
Format_DateTime(tim1[3],BUFFER1+6);
Format_DateTime(tim1[2],BUFFER2);
Format_DateTime(tim1[1],BUFFER2+3);
Format_DateTime(tim1[0],BUFFER2+6);
show_string("BUFFER1",32,2,1);
show_string(BUFFER2,32,4,0);
//break;
}
else
show_string("A",6,0,0);
// case 2:
if(tnum==2)
{ while(kest!=1)
{
show_string("B",14,0,1);
Format_DateTime(tim2[5],BUFFER1);
Format_DateTime(tim2[4],BUFFER1+3);
Format_DateTime(tim2[3],BUFFER1+6);
Format_DateTime(tim2[2],BUFFER2);
Format_DateTime(tim2[1],BUFFER2+3);
Format_DateTime(tim2[0],BUFFER2+6)
show_string(BUFFER1,32,2,1);
show_string(BUFFER2,32,4,0);
}
}
//break;
else
show_string("B",14,0,0);
//case 3:
if(tnum==3)
{
clear();
show_string("C",22,0,1);
Format_DateTime(tim3[5],BUFFER1);
Format_DateTime(tim3[4],BUFFER1+3);
Format_DateTime(tim3[3],BUFFER1+6);
Format_DateTime(tim3[2],BUFFER2);
Format_DateTime(tim3[1],BUFFER2+3);
Format_DateTime(tim3[0],BUFFER2+6);
show_string(BUFFER1,32,2,1);
show_string(BUFFER2,32,4,0);
// break;
}
else
show_string("C",22,0,0);
//case 4:
if(tnum==4)
{
show_string("D",30,0,1);
Format_DateTime(tim4[5],BUFFER1);
Format_DateTime(tim4[4],BUFFER1+3);
Format_DateTime(tim4[3],BUFFER1+6);
Format_DateTime(tim4[2],BUFFER2);
Format_DateTime(tim4[1],BUFFER2+3);
Format_DateTime(tim4[0],BUFFER2+6);
show_string(BUFFER1,32,2,1);
show_string(BUFFER2,32,4,0);
//break;
}
else
show_string("D",30,0,0);
/*case 5:
show_string("E",38,0,1);
Format_DateTime(tim5[5],BUFFER1);
Format_DateTime(tim5[4],BUFFER1+3);
Format_DateTime(tim5[3],BUFFER1+6);
Format_DateTime(tim5[2],BUFFER2);
Format_DateTime(tim5[1],BUFFER2+3);
Format_DateTime(tim5[0],BUFFER2+6);
show_string(BUFFER1,32,2,1);
show_string(BUFFER2,32,4,0);
break;
case 6:
show_string("F",46,0,1);
Format_DateTime(tim6[5],BUFFER1);
Format_DateTime(tim6[4],BUFFER1+3);
Format_DateTime(tim6[3],BUFFER1+6);
Format_DateTime(tim6[2],BUFFER2);
Format_DateTime(tim6[1],BUFFER2+3);
Format_DateTime(tim6[0],BUFFER2+6);
show_string(BUFFER1,32,2,1);
show_string(BUFFER2,32,4,0);
break;
case 7:
show_string("G",54,0,1);
Format_DateTime(tim7[5],BUFFER1);
Format_DateTime(tim7[4],BUFFER1+3);
Format_DateTime(tim7[3],BUFFER1+6);
Format_DateTime(tim7[2],BUFFER2);
Format_DateTime(tim7[1],BUFFER2+3);
Format_DateTime(tim7[0],BUFFER2+6);
show_string(BUFFER1,32,2,1);
show_string(BUFFER2,32,4,0);
break;
case 8:
show_string("H",60,0,1);
Format_DateTime(tim8[5],BUFFER1);
Format_DateTime(tim8[4],BUFFER1+3);
Format_DateTime(tim8[3],BUFFER1+6);
Format_DateTime(tim8[2],BUFFER2);
Format_DateTime(tim8[1],BUFFER2+3);
Format_DateTime(tim8[0],BUFFER2+6);
show_string(BUFFER1,32,2,1);
show_string(BUFFER2,32,4,0);
break;
case 9:
show_string("I",168,0,1);
Format_DateTime(tim9[5],BUFFER1);
Format_DateTime(tim9[4],BUFFER1+3);
Format_DateTime(tim9[3],BUFFER1+6);
Format_DateTime(tim9[2],BUFFER2);
Format_DateTime(tim9[1],BUFFER2+3);
Format_DateTime(tim9[0],BUFFER2+6);
show_string(BUFFER1,32,2,1);
show_string(BUFFER2,32,4,0);
break;
case 10:
show_string("J",76,0,1);
Format_DateTime(tim10[5],BUFFER1);
Format_DateTime(tim10[4],BUFFER1+3);
Format_DateTime(tim10[3],BUFFER1+6);
Format_DateTime(tim10[2],BUFFER2);
Format_DateTime(tim10[1],BUFFER2+3);
Format_DateTime(tim10[0],BUFFER2+6);
show_string(BUFFER1,32,2,1);
show_string(BUFFER2,32,4,0);
break;
default :break;*/
//}
if(tnum==1)
tnum=4;
tnum--;
}
else
show_string("ABCDEFGHIJ",6,0,0);
}
} |