基于DS1302+LCD1602的數(shù)字萬年歷,,具有按鍵可調(diào)功能
主程序流程圖:
按鍵掃描過程中,用了三個(gè)鍵:
key0(功能鍵)
key1(增大鍵)
key2(減小鍵)
用變量num記錄功能鍵按下次數(shù)
switch(num)
{
case 1: flag=1;//修改時(shí)間,,禁止液晶從DS1302讀數(shù)據(jù)
LCD_WRITE_COM(0x0f);//光標(biāo)開始閃爍
LCD_WRITE_COM(0x80+3);//第一次按下,光標(biāo)定位到年位置
break;
case 2: LCD_WRITE_COM(0x80+6);//第二次按下,,光標(biāo)定位到月位置
break;
case 3: LCD_WRITE_COM(0x80+9);//第三次按下,,光標(biāo)定位到日位置
break;
case 4: LCD_WRITE_COM(0x80+12);//第四次按下,光標(biāo)定位到星期位置
break;
case 5: LCD_WRITE_COM(0x80+0x40+4);//第五次按下,,光標(biāo)定位到時(shí)位置
break;
case 6: LCD_WRITE_COM(0x80+0x40+7);//第六次按下,,光標(biāo)定位到分位置
break;
case 7: LCD_WRITE_COM(0x80+0x40+10);//第七次按下,光標(biāo)定位到秒位置
break;
case 8: num=0;//第八次按下,,記錄清零
LCD_WRITE_COM(0x0c);//不顯示光標(biāo)
WRITE_1302(WRITE_PROTECT,0x00);//禁止寫保護(hù)
WRITE_1302(0x80,(second/10*16)+second%10);//將調(diào)節(jié)后的秒寫入DS1302
WRITE_1302(0x82,(minute/10*16)+minute%10);//將調(diào)節(jié)后的分寫入DS1302
WRITE_1302(0x84,(hour/10*16)+hour%10);//將調(diào)節(jié)后的時(shí)寫入DS1302
WRITE_1302(0x8a,(week/10*16)+week%10);//將調(diào)節(jié)后的星期寫入DS1302
WRITE_1302(0x86,(day/10*16)+day%10);//將調(diào)節(jié)后的日寫入DS1302
WRITE_1302(0x88,(month/10*16)+month%10);//將調(diào)節(jié)后的月寫入DS1302
WRITE_1302(0x8c,(year/10*16)+year%10);//將調(diào)節(jié)后的年寫入DS1302
WRITE_1302(WRITE_PROTECT,0x80);//開寫保護(hù)
flag=0;//時(shí)間修改完畢,,允許液晶從DS1302讀數(shù)據(jù)
break;
}
仿真時(shí)的現(xiàn)象: