能帮我解决个问题么、DS1302在12864上显示时钟后。怎么加入按键调节时间啊。最好是ICC编译

51也行、急救急救急救。。。!!!悬赏好商量
2024-11-16 05:24:16
推荐回答(1个)
回答(1):

当有按键按下时 停止1302 然后更改寄存器数值,再接着读取寄存器数值显示,然后开启1302就好了,这些操作都得放到键盘扫描中,设置一个标志,当有按键按下是停止主函数中的大循环

void key_scan()
{
P31=0;//将232的键盘引脚设为0 将跳线变?

if(P04==0)
{ send_com(0x0f);
jianpanF=1;
delay(5); //去斗

if(P04==0)
{
while(P04==0); //等待按键松开再加一
sj_para++;
send_com(0x0f);
if(sj_para==7) {sj_para=0;} //选择时间参?
switch (sj_para)
{
case 1:
send_addr(3, 0);
send_data(table[Read_DS1302(0x85)/10]); //读小时
send_data(table[Read_DS1302(0x85)%10]);
send_addr(3, 0);
break;
case 2:
send_addr(3, 2);
send_data(table[Read_DS1302(0x83)/10]); //读分钟
send_data(table[Read_DS1302(0x83)%10]);
send_addr(3, 2);
break;
case 3:
send_addr(3, 4);
send_data(table[Read_DS1302(0x81)/10]); //读秒
send_data(table[Read_DS1302(0x81)%10]);
send_addr(3, 4);
break;
case 4:
send_addr(2, 1);
send_data(table[Read_DS1302(0x8d)/10]); //读年
send_data(table[Read_DS1302(0x8d)%10]);
send_addr(2, 1);
break;
case 5:
send_addr(2, 3);
send_data(table[Read_DS1302(0x89)/10]); //读月
send_data(table[Read_DS1302(0x89)%10]);
send_addr(2, 3);
break;
case 6:
send_addr(2, 5);
send_data(table[Read_DS1302(0x87)/10]); //读日
send_data(table[Read_DS1302(0x87)%10]);
send_addr(2, 5);
break;
}
}
}
if(P05==0)
{
delay(5); //去斗
if(P05==0)

{
while(P05==0); //等待按键松开再加一

jianpanF=1; //时间调节
switch (sj_para) //在这里为了能显示光标 在键盘中加入读取数据和显示数据的程序
{
case 1: shi=Read_DS1302(0x85)+1;
if(shi>=25) shi=0; modify_time(0x84,shi);
send_data(table[Read_DS1302(0x85)/10]); //读小时
send_data(table[Read_DS1302(0x85)%10]);
send_addr(3, 0); //时
break;
case 2: fen=Read_DS1302(0x83)+1;
if(fen>=60)fen=0; modify_time(0x82,fen);
send_data(table[Read_DS1302(0x83)/10]); //读分钟
send_data(table[Read_DS1302(0x83)%10]);
send_addr(3, 2);
break; //分
case 3:
miao=Read_DS1302(0x81)+1;
if(miao>=60) miao=0; modify_time(0x80,miao);
send_data(table[Read_DS1302(0x81)/10]); //读秒
send_data(table[Read_DS1302(0x81)%10]);
send_addr(3, 4);
break; //秒

case 4:
nian=Read_DS1302(0x8d)+1;
if(nian>=99) nian=0; modify_time(0x8c,nian);
send_data(table[Read_DS1302(0x8d)/10]); //读年
send_data(table[Read_DS1302(0x8d)%10]);
send_addr(2, 1);
break; //秒
case 5:
yue=Read_DS1302(0x89)+1;
if(yue>=12) yue=0; modify_time(0x88,yue);
send_data(table[Read_DS1302(0x89)/10]); //读月
send_data(table[Read_DS1302(0x89)%10]);
send_addr(2,3);
break; //秒
case 6:
ri=Read_DS1302(0x87)+1;
if( ri>=31) ri=0; modify_time(0x86, ri);
send_data(table[Read_DS1302(0x87)/10]); //读日
send_data(table[Read_DS1302(0x87)%10]);
send_addr(2, 5);
break; //秒
}

}
}
if(P06==0)
{ delay(5);
if(P06==0);
while(P06==0);
send_com(0x0c);
if(jianpanF==1)
jianpanF=0;
send_com(0x01); // 清空DDRAM
send_addr(1, 0);
for(q=0;q<6;q++)
{
send_data(wendu[q]);
}
send_addr(2, 0);
for ( q=0;q<14;q++)
{
send_data(shijian[q]);
}
}

}