Digital Clock DS1307LCD

Selain dengan dot LED, digital clock dapat di tampilkan dengan sebuah LCD.

digital clock LCD

Digital clock di atas di bangun dengan komponen utama Mikrokontrol dari Microchip, PIC16F628A yang di program dengan software mikroC  kompiler. Dan sebuah Real Time Clock DS1307.

Berikut gambar skema rangkaiannya.

Proteus DS1307 LCD OK

Dan program berikut dapat di pakai untuk menjalankan rankaian di atas.

/********************************************************/

// ———————–Configuration Soft_I2C connections
sbit Soft_I2C_Scl           at RA1_bit;
sbit Soft_I2C_Sda           at RA0_bit;
sbit Soft_I2C_Scl_Direction at TRISA1_bit;
sbit Soft_I2C_Sda_Direction at TRISA0_bit;
// ———————–End configuration Soft_I2C connections

// ———————–Configutation LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// ———————-End configuration LCD module connections

unsigned short seconds, minutes, hours, day, date, month, year, SQW;

//———————–Write time and date information from RTC DS1307 by Soft_I2C
void Write_Time() {

Soft_I2C_Start();         // Issue start signal
Soft_I2C_Write(0xD0);
Soft_I2C_Write(0);

//—–Write Time hours:minutes:seconds, date/month/year
Seconds = Soft_I2C_Write(0x59);      // Write 59 seconds
minutes = Soft_I2C_Write(0x30);     // Write 30 minutes
hours   = Soft_I2C_Write(0x12);      // Write 12 hours
day     = Soft_I2C_Write(0x06);      // Write day 6th
date    = Soft_I2C_Write(0x08);      // Write date 8th
month   = Soft_I2C_Write(0x06);     // Write month 6th
year    = Soft_I2C_Write(0x12);      // Write year 12th
SQW     = Soft_I2C_Write(10010000);    // SQW Eneble @1Hz
Soft_I2C_Stop();      // Issue stop signal
}

//———————–Reads time and date information from RTC DS1307 by Soft_I2C

void Read_Time() {

Soft_I2C_Start();       // Issue start signal
Soft_I2C_Write(0xD0);
Soft_I2C_Write(0);
Soft_I2C_Start();         // Issue start signal
Soft_I2C_Write(0xD1);

//—–Read Time hours:minutes:seconds, date/month/year
Seconds = Soft_I2C_Read(1);      // Read seconds byte
minutes = Soft_I2C_Read(1);      // Read minutes byte
hours = Soft_I2C_Read(1);          // Read hours byte
day = Soft_I2C_Read(1);             // Read day byte
date = Soft_I2C_Read(1);           // Read date byte
month = Soft_I2C_Read(1);       // Read month byte
year = Soft_I2C_Read(1);         // Read year byte
Soft_I2C_Read(0);                     // Read not acknowledge byte
Soft_I2C_Stop();                          // Issue stop signal
}

//——————– Formats date and time
void Transform_Time() {

seconds  =  ((seconds & 0x70) >> 4)*10 + (seconds & 0x0F);    // Transform seconds
minutes  =  ((minutes & 0x70) >> 4)*10 + (minutes & 0x0F);   // Transform months
hours    =  ((hours & 0x30)  >> 4)*10  + (hours & 0x0F);     // Transform hours
day      =  (day & 0x07 );     // Transform day
date     =  ((date & 0x30) >> 4)*10    + (date & 0x0F);     // Transform date
month    =  ((month & 0x10)  >> 4)*10  + (month & 0x0F);      // Transform month
year     =  ((year & 0xF0) >> 4 )*10   + (year & 0x0F);   // Transform year
}

//——————– Output values to LCD
void Display_Time() {

Lcd_Chr(1, 6, (date / 10)   + 48);  // Print tens digit of day
Lcd_Chr(1, 7, (date % 10)   + 48);    // Print ones digit of day

Lcd_Chr(1, 9, (month / 10)  + 48);    // Print tens digit of month

Lcd_Chr(1,10, (month % 10)  + 48);   // Print ones digit of day

Lcd_Chr(1,14, (year / 10)  + 48);     // Print tens year
Lcd_Chr(1,15, (year % 10 ) + 48);     // Print ones year

Lcd_Chr(2, 6, (hours / 10)    + 48);    // Print tens digit of hours
Lcd_Chr(2, 7, (hours % 10 )   + 48);    // Print ones digit of hours
Lcd_Chr(2, 9, (minutes /10 )  + 48);    // Print tens digit of minutes

Lcd_Chr(2,10, (minutes %10 )  + 48);    // Print ones digit of minutes
Lcd_Chr(2,12, (seconds / 10)  + 48);    // Print tens digit of seconds

Lcd_Chr(2,13, (seconds % 10)  + 48);    // Print oness digit of seconds

}

//—————— Performs project-wide init
void Init_Main() {
TRISA=0;
PORTA=0;

TRISB = 0;
PORTB = 0xFF;
CMCON = 0x07;     // Comparator off for PIC 16F628A

Soft_I2C_Init();     // Initialize Soft I2C communication
Lcd_Init();                      // Initialize LCD
Lcd_Cmd(_LCD_CLEAR);        // Clear LCD display
Lcd_Cmd(_LCD_CURSOR_OFF);       // Turn cursor off

Lcd_Out(1,1,”TGL :”);     // Prepare and output static text on LCD
Lcd_Chr(1,8,’-‘);
Lcd_Chr(1,11,’-‘);
Lcd_Out(2,1,”JAM :”);
Lcd_Chr(2,8,’:’);
Lcd_Chr(2,11,’:’);
Lcd_Out(1,12,”20″);      // start from year 20__
}

//—————– Main procedure
void main() {
Delay_ms(500);
Init_Main();      // Perform initialization
Write_Time();

while (1) {               // Endless loop
Read_Time();
Transform_Time();      // Trasform time after read signal
Display_Time();           // Prepare and display on LCD
}   // End while
}   // End main

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google

You are commenting using your Google account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s