1602LCD digital electronic clock basic design ideas:
Keywords:1602LCD
Reference address:1602LCD digital electronic clock C language
1. 1602 LCD display:
First line: Year, Month, Day 2012-01-22
Second line: hours, minutes, seconds 23:59:00
2. Independent button functions:
Key1 restores the actual time before the MCU adjusts the time. Since timer T0 is paused during the time adjustment, timer T1 is started to ensure that the time of the MCU is correct. (That is, cancel the time adjustment)
Key2 enters the time adjustment state: stop timer T0 and start timer T1.
Key3 exits the time adjustment state: starts timer T0 and stops timer T1.
Key4 Select to adjust the time: Seconds, Minutes, Hours, Days, Months, Years
Key5 Timing adjustment: Incremental and start the buzzer
Key6 Time adjustment: Decrease and start buzzer
It took me two and a half days to finally realize the clock according to my design ideas. During these two days, I felt that the most difficult thing was that when an error occurred, I didn't know how to debug it. Some errors could not be debugged, so I often had to think about the problem in a different direction. So when faced with confusion, I had to test it. I could only solve my own mistakes because it was often difficult for others to understand my mistakes. Alas, it was really lonely to struggle alone like me. When I encountered confusion, I either gave up or persisted, but I didn't know how long I would persist. I was always afraid of wasting time like this.
At present, there is still a problem that has not been solved: if the time is adjusted unreasonably, the original time must be restored and there will be an error prompt.
For example, if the time is: 2012-2-34, if you change it to this date, there must be an error message and the time must be cancelled.
#include
#include "MyFuntion.h" //Custom header file
//Scan whether these buttons are pressed
void Keycan()
{
if(Key1==0) //Enter the time adjustment state
{
Delay();
if(Key1==0) //Stop timer T0 and start timer T1
{
ButtonBeep();
SaveCurrentTime(); //When entering the time adjustment state, the current time must be saved. If the time adjustment is canceled, the time can be restored
TR0=0; //Stop timer T0
TR1=1; //Start timer T1
tempSecond=0;
}
while(!Key1);
}
if(Key2==0)
{
Delay();
if(Key2==0) //Cancel the time adjustment and restore the actual time before the MCU adjustment
{
if(TR0==0) //Restore time in the time adjustment state
{
ButtonBeep();
CurrentTime();
}
}
while(!Key2);
}
if(Key3==0) //Exit time adjustment state:
{
Delay();
if(Key3==0)
{
ButtonBeep(); //Stop timer T1 and start timer T0
TR0=1; //Start timer T0
TR1=0; //Stop timer T1
Write_Command(0x0c); //Set to display or not to display cursor
}
while(!Key3);
}
//When timer T0 stops, the following buttons can be operated
if(TR0==0) //Timer T0 stops
{
if(Key4==0) // Key4 controls the cursor to move right
{
Delay();
if(Key4==0)
{
AdjustCursorRight(); //Control the cursor to move right
ButtonBeep();
}
while(!Key4);
}
if(Key5==0) // Key5 controls the cursor to move left
{
Delay();
if(Key5==0)
{
AdjustCursorLeft(); //Control the cursor to move left
ButtonBeep();
}
while(!Key5);
}
if(Key6==0) // increment
{
Delay();
if(Key6==0)
{
UpDown=1;
ButtonSetTime();
ButtonBeep();
}
while(!Key6);
}
if(Key7==0) // decrement
{
Delay();
if(Key7==0)
{
UpDown=0;
ButtonSetTime();
ButtonBeep();
}
while(!Key7);
}
}
}
void main()
{
TMOD=0X01;
EA=1;
ET0=1;
ET1=1;
TR0=1; //Start timer T0
// TR1=0; //Stop timer T1, that is, temporarily do not start timer T1
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
InitLCD(); //Initialize LCD
Init_Table_YMD(table1); // LCD timetable year, month, day
Init_Table_HMS(table2); // LCD timetable hours, minutes, seconds
DisplayLCD_YMD(table1, 10); //LCD displays the year, month, and day
DisplayLCD_HMS(table2, 8); //LCD displays time in hours, minutes and seconds
while(1)
{
Keycan();
if(t0==20)
{
t0=0;
IncreaseHMS(); // hours, minutes, seconds increase
}
}
}
//Timer T0 realizes automatic timing
void LCD_Timer0() interrupt 1 using 0
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t0++;
}
//Timer T1 realizes automatic timing to reduce the error caused by adjusting the time
void LCD_Timer1() interrupt 3 using 1
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
t1++;
if(t1==20)
{
t1=0;
tempSecond++;
}
}
Previous article:How to realize DS1302 real-time clock display on 1602 LCD
Next article:How to program a digital electronic clock using 1602 LCD
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
Guess you like
- I have a problem with using the eclipse that comes with altera. Can anyone tell me what I have used?
- The Three Realms of Oscilloscopes
- Problems with the snubber circuit
- Hardware Emulation
- [RVB2601 Creative Application Development] Introduction and use of cJSON for RVB2601
- I bought an ST-LINK emulator for SensorTile.box for 19 RMB
- How to set the clearance of ALTIUM without affecting the copper coating
- Common RF Certification Systems
- [RVB2601 Creative Application Development] VII. RVB2601 Sound Recognition Preliminary Test
- Smart Home Energy Management with Levarys and Qorvo Technologies