In this tutorial we will learn how to make Digital Clock use PIC Microcontroller. It very easy to make. Digital Clock show the digit at display. The Clock show hour,minute and second. Here I am use PIC16F877A Microcontroller and mikroC PRO for PIC  for Code editing.

You can watch the following video or read the written tutorial below.




The Digital Clock show three parameter. They are second, minute and hour. The three parameter depend on each other. The hour depend on minute and minute depend on second. The second is change per second and than it value 60 the second is reset and increase the minute. The minute change per 60 second and when minute reached 60 than minute is reset  and increase the our value.

 

 

Digital Clock part 2

Digital Clock part 3



Circuit Diagram:

 

 

Source code

// Lcd module connection
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;

sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
// End Lcd module connection
char text(int a){
     switch(a){
               case 0:
                    return '0';
               case 1:
                    return '1';
               case 2:
                    return '2';
               case 3:
                    return '3';
               case 4:
                    return '4';
               case 5:
                    return '5';
               case 6:
                    return '6';
               case 7:
                    return '7';
               case 8:
                    return '8';
               case 9:
                    return '9';
               }
     }

int second= 0;
int minute = 0;
int hour = 0;
void main() {
     char *time = "00:00:00";
     Lcd_Init();                                                  // Initialize Lcd module
     Lcd_Cmd(_LCD_CLEAR);                         // Clear Lcd display
     Lcd_Cmd(_LCD_CURSOR_OFF);               // Lcd cursor off
     Lcd_Out(1,3,"Developed By");
     Lcd_Out(2,1,"MINA TECHNOLOGY");
     delay_ms(2000);                                                 // 2second delay
     Lcd_Cmd(_LCD_CLEAR);                                 // Clear Lcd display
     Lcd_Out(1,3,"Digital Clock");
     hour = 1;
     while(1){
              second++;
              if(second>=60){
                             minute++;
                             second = 0;
                             }
              if(minute>=60){
                             hour++;                                           // Increase the hour value
                             minute = 0;                                      // Clear minute
                             }
              if(hour>=13) hour = 1;                                     // Reset hour
              time[0] =text(hour / 10);                                   // Left digit of hour
              time[1] =text(hour % 10);                               // Right digit of hour
              time[3] = text(minute / 10);                               // Left digit of minute
              time[4] = text(minute % 10 );                            // Right digit of minute
              time[6] = text(second / 10);                                // Left digit of second
              time[7] = text(second % 10);                             // Right digit of second
              Lcd_Out(2,4,time);                                        // show time value
              delay_ms(1000);                                              // 1s delay
              }

}

 

 

 

Download free source code

 

download