Digital perpetual calendar based on DS1302+LCD1602, with button adjustable function

Digital perpetual calendar based on DS1302+LCD1602, with button adjustable function

Main program flow chart:

Digital perpetual calendar based on DS1302+LCD1602, with button adjustable function

During key scanning, three keys are used:

key0 (function key)

key1 (increase key)

key2 (decrease key)

Use the variable num to record the number of times the function key is pressed

switch(num)

{
case 1: flag=1;//Modify time, prohibit LCD from reading data from DS1302
LCD_WRITE_COM(0x0f);//The cursor starts to blink
LCD_WRITE_COM(0x80+3);//Press for the first time, the cursor is positioned to the year position
break;

case 2: LCD_WRITE_COM(0x80+6);//Press the second time, the cursor is positioned to the month position
break;

case 3: LCD_WRITE_COM(0x80+9);//Press the third time, the cursor is positioned to the day position
break;
case 4: LCD_WRITE_COM(0x80+12);//Press the fourth time, the cursor is positioned to the week position
break;
case 5: LCD_WRITE_COM(0x80+0x40+4);//Press the fifth time, the cursor is positioned at the time
break;

case 6: LCD_WRITE_COM(0x80+0x40+7);//Press the sixth time, the cursor is positioned to the minute position
break;

case 7: LCD_WRITE_COM(0x80+0x40+10);//Press the seventh time, the cursor is positioned to the second position
break;

case 8: num=0;//The eighth press, the record is cleared
LCD_WRITE_COM(0x0c);//Do not Display the cursor
WRITE_1302(WRITE_PROTECT,0x00);//Disable write protection
WRITE_1302(0x80,(second/10*16)+second%10);//Write the adjusted seconds to DS1302
WRITE_1302(0x82,(minute/10*16)+minute%10);//Write the adjusted minutes to DS1302
WRITE_1302(0x84,(hour/10*16)+hour%10);//Write the adjusted time to DS1302
WRITE_1302(0x8a,(week/10*16)+week%10);//Write the adjusted week to DS1302
WRITE_1302(0x86,(day/10*16)+day%10);//Write the adjusted day to DS1302

WRITE_1302(0x88,(month/10*16)+month%10);//Write the adjusted month to DS1302

WRITE_1302(0x8c,(year/10*16)+year%10);//Write the adjusted year to DS1302

WRITE_1302(WRITE_PROTECT,0x80);//Open write protection

flag=0;//The time is modified, allowing the LCD to read data from DS1302

break;

}

Phenomenon during simulation:

The Links:   LQ190E1LX78 2SC0435T2A0-17