In: Computer Science
Digital Clock with LCD Display
write the code for the function header:
#include "mbed.h"
#include "TextLCD.h"
1. In this lab, you will redo a digital clock this time with the LCD display and in the format of HH:MM:SS (HH is the hour from 0 -- 23, and MM is the minute from 00 -- 59, and SS is the second from 00-59)
2. Design the circuit that properly connects the LCD display to the mbed platform. Include your connection diagram in the Experiment Results of your lab report.
3. Based on the hardware design from step 2, design your code to implement the digital clock. Upon reset of the board, the clock should reset to 00:00:00, then changed to 00:00:01 after 1 second, and 00:00:02 after another second, etc.
4. Test your digital clock with an accurate clock (e.g. the clock in the computer). Explain the test process and what you observe while carrying out the test process. Is your digital clock accurate? If it is not, explain what you think might be the cause of the inaccuracy. "Calibrate" your digital clock by modifying your code to be as close to the accurate clock as possible. Include the details of your calibration process in your lab report.
I am more interested in the coding. Thanks
//above diagrame i take from google. its daigrame of 16x2 lcd
#include "mbed.h"
#include "TextLCD.h"
TextLCD lcd(p19, p20, p21, p22, p23, p24);
DigitalIn reset_button(USER_BUTTON); // for button on the board
int hours, minutes, seconds;
int main() {
hours=0;
minutes=0;
seconds=0;
while(1)
{
if(reset_button==0) // for reseting press the button on the board
then all parameter get reseted
{
hours=0;
minutes=0;
seconds=0
}
if(seconds==60)
{ seconds=0;
minutes++;
}
if(minutes==60)
{ minutes=0;
hours++;
}
if(hours==24)
{ hours=0;
}
lcd.locate(0, 2); // row 2, column 0
// show time, use 2 positions per field, show leading zeros
lcd.printf("%02d:%02d:%02d", hours, minutes, seconds); //to
printing the values in lcd
seconds++; //second increases after one second
wait(1);
//wait apply for wait one second
/*but output is not accurate with compare to the real
clock
becouse some above instruction take time to execute to calculate
the time taken by each
of them needs knowledge of mbed board frequecy
*/
//but its near about real clock so you just vary waiting time to
get real time clock
/*in case of any problem or any help leave comment i can give the
real parameters becouse it needs time to check*/
}
}