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. In previous tutorial we seen how to  make simple digital Clock. In this project we are modify our previous project. Here In this project I am insert set and up button for setting the.actual time.  I am use PIC16F877A Microcontroller and Mikro C 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.
 

 

Make Digital Clock part 1

Make 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;
unsigned short set;
unsigned short set_state=0;
int i = 0;
char *time = "00:00:00";
void main() {
     TRISC = 0x03 ;
     PORTC = 0X00;
     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;
     //set_state = 0;
     while(1){
              set = 0;
              if(PORTC.F0==1){
                              delay_ms(100);
                              if(PORTC.F0==1){
                                              set_state++;
                                              if(set_state>=4) set_state = 0;
                                              }
                              }
              if(set_state){
                            if(PORTC.F1==1){
                                            set = 1;
                                            }
                            if(set_state && set){
                                         switch(set_state){
                                                           case 1:
                                                                hour = hour + set;          // Increase hour value
                                                                break;
                                                           case 2:
                                                                minute = minute + set;         // Increase minute value
                                                                break;
                                                           case 3:
                                                                second = 0;                     // clear second value
                                                                break;

                                                           }
                                         }
                            }


              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
                           i = ~i;
                           }
              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); 
              if(i==0)Lcd_Out(2,14,"AM");
              if(i)Lcd_Out(2,14,"PM");                  // show time value
              delay_ms(1000);          // 1s delay
              }


}

 

 

 

Download free source code

 

download