Introduction
A digital clock is a clock that displays time in numbers rather than hands on a dial. The first digital clock was invented by Josef Pallweber which used the “jump-hour” mechanism in 1883. The working principle of his clock is the use of rotating discs which displayed the hour and minutes. Since his invention, there has been a rapid development of digital clocks.
Digital clocks typically use oscillation of AC power (50 Hz / 60 Hz) or 32.768 kHz crystal oscillator as seen in quartz clock to keep time. We have two different display formats for digital clock namely: 24-hour format or 12-hour format. Liquid crystal display is used by some of the clocks while others use 7 segment display.
Design
The proposed digital clock uses a dedicated micro controller and a 20 MHz crystal oscillator. A 16×2 LCD is used to display the time. A keypad is used to set the time. Here we used the sinus board to design a digital clock. The schematic for the digital clock is shown
The source code is developed using mikroc pro.
//PROGRAM WRITTEN BY NDUKWE SAMUEL C.
//SAMSONIC TECHNOLOGIES AND CONSULTS
//digital clock USING PIC18
#define ok PORTD.F6
#define up PORTD.F7
#define down PORTD.F5
#define pressed 0
//LCD module connections--------------------------------------------------------
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
int counter = 0;
int sec = 0;
int minu = 0;
int hr = 0;
int num = 0;
char *hrTM = "00";
char *minuTM = "00";
char *secTM = "00";
void Interrupt(){
if(TMR0IF_bit){
TMR0IF_bit = 0;
TMR0H = 0XEC;
TMR0L = 0X78;
counter++;
if (counter == 1000){
counter = 0;
sec++;
}
if (sec == 60){
sec = 0;
minu++;
}
if(minu == 60){
minu = 0;
hr++;
}
if(hr == 24){
hr = 0;
}
if(hr<0) hr = 0;
if(minu < 0) minu = 0;
}
}
void setting(){
if(ok == pressed){
num++;
delay_ms(200);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
}
if (num == 3) num = 0;
switch (num){
case 1: LCD_Out(2,1,"^^");
if(up == pressed) {
hr++;
delay_ms(200);
}
if(down == pressed){
hr--;
delay_ms(200);
}
break;
case 2: LCD_Out(2,4,"^^");
if(up == pressed) {
minu++;
delay_ms(200);
}
if(down == pressed){
minu--;
delay_ms(200);
}
break;
case 3: num = 0;
break;
}
}
void main(){
T0CON = 0X88;
TMR0H = 0XEC;
TMR0L = 0X78;
GIE_bit = 1;
TMR0IE_bit = 1;
TRISD.F5 = 1;
TRISD.F6 = 1;
TRISD.F7 = 1;
PORTD.F5 = 0;
PORTD.F6 = 0;
PORTD.F7 = 0;
ADCON1 = 0b00000111;
LCD_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
hr = 10;
minu = 58;
sec = 0;
while(1){
setting();
LCD_OUT(1,3, ":");
LCD_OUT(1,6, ":");
secTm[0] = (sec/10) + 48;
secTm[1] = (sec%10) + 48;
minuTm[0] = (minu/10) + 48;
minuTm[1] = (minu%10) + 48;
hrTm[0] = (hr/10) + 48;
hrTm[1] = (hr%10) + 48;
LCD_OUT (1,1, hrTm);
LCD_OUT (1,4, minuTm);
Lcd_OUT (1,7, secTm);
}
}
working video :