Digital LCD Clock

By Jessica Schlauderaff

Overview

This project is a digital clock with an LCD display. This clock must be plugged into the wall via a micro-USB connector in order to display correctly. The first line of the clock displays the current time in standard time with an AM or PM at the end. The second line of the clock displays the date in dd/mm/yy format. The clock also has alarm capabilities.

Front view

Hardware

The clock uses a Renesas RL78 microcontroller. The display used is a Newhaven LCD 2x8 character display with backlight. The DS3231MZ real-time clock is used to keep track of the time. The clock is powered by a micro-USB connector, as mentioned above, and the real-time clock is powered by a CR2032 battery when the clock is not plugged into the wall and displaying time. The clock contains three buttons, which are used to set display time and alarm time and are described in the software section. Finally, there is a buzzer which alerts the user that the alarm time has arrived.

Schematic Board layout

Software

The code for the clock is written in assembly. When started, the clock runs through a setup routine. Along with setting things up for communication, this routine also sets up interrupts. The main program loop checks the three buttons to see if they are pressed and runs through the finite state machine based on the buttons. On the first run through of the loop, this is typically ignored as the clock finishes "setup". The final steps for setup/turning on the clock are getting the time from the RTC and displaying the time and date on the LCD screen. After this process, the alarm is checked, but - similar to the buttons - the first run through of the loop is unlikely to have an alarm set. That is the end of the first main loop.

Within the main loop subsequently, the microcontroller is put to sleep and woken up after a 16 ms period by the 12-bit timer. When awake, the clock checks the three buttons, taking switch debouncing into account. All of the check button methods are similar and change the button state variable related to one of the three buttons if it is pushed.

The next part of the main loop calls the finite state machine. The buttons and their other names/functions are:

The finite state machine first locates the current mode (0 = display time, 1 = set hours, 2 = set minutes, 3 = set day, 4 = set month, 5 = set year, 6 = set alarm hrs, 7 = set alarm mins), and then jumps to that mode's state button methods. Within that state, the statuses of all three buttons are checked. If the state of a button is "pressed", its actions can be seen below and in the source code.

states

The process for setting the clock's alarm time is seen in the finite state machine and is similar to the methods for setting the regular time. To get to that option, button A and C must be pressed. To check when the alarm goes off, at the end of every main loop, a method is called which compares the current time to the alarm time variables. If they match, then the AlarmOn variable is set and, at the start of the next main loop, the program calls a method to signal the buzzer. The C Button can turn off the alarm if the clock is in state 0.

Downloads


Last modified:Mon, Jan 23, 2023.

00260