Você está na página 1de 14

Real time digital clock

Prepared By
Reem Hashim Layal Khalid Hanan Mohammad 09120005 09120012 09120037

Supervised by
Miss Atiya Azmi

Abstract: This application note is intended to demonstrate an application using the DS1307 real-time clock (RTC) with a Microchip PIC microcontroller )PIC18F4550). The software example includes basic operating routines. A schematic of the application circuit is included.

Overall Description Of the System In this project we used pic 184550 with a help of using DS1307 which is for generating the time, choosing the mode of it like whether it's 12 or 24 and for showing the word: DTAE: YEAR/MONTH/DAY" "TIME: HOURS/MINITS/ SECONDS In the LCD lm016l which type is 2x16, we will get the output like the above DATE &TIME. Also, we used two crystals one is for the PIC and the other for the DS1307. We used three switches to adjust the time. We used one capacitor for each crystal. We provided two voltages (3v), one connected with PIC and the other with DS1307. We used five resistors each one is 10 k ohm as showing in the circuit diagram below

Problem Statement The project statement is to design a Real Time Clock with accuracy in time and date up to year 2100 with leap year compensation. In our project we are interfaced microcontroller with Real Time Clock chip by I2C protocol along with LCD display for visualization. The block diagram shown below gives an idea about how we done this.

System Block Diagram:

Figure1: system block diagram

Schematics of the Systems:

Figure2:Schematics of the Systems

Flowchart :

Code of the microcontroller software:


#ifndef DS1307 #define DS1307 0xD0 #endif // Software I2C connections sbit Soft_I2C_Scl at RB1_bit; sbit Soft_I2C_Sda at RB0_bit; sbit Soft_I2C_Scl_Direction at TRISB1_bit; sbit Soft_I2C_Sda_Direction at TRISB0_bit; // End Software I2C connections sbit LCD_RS at RB3_bit; sbit LCD_RW at RD0_bit; sbit LCD_EN at RB2_bit; sbit LCD_D4 at RD1_bit; sbit LCD_D5 at RD2_bit; sbit LCD_D6 at RD3_bit; sbit LCD_D7 at RD4_bit; sbit LCD_RS_Direction at TRISB3_bit; sbit LCD_RW_Direction at TRISD0_bit; sbit LCD_EN_Direction at TRISB2_bit; sbit LCD_D4_Direction at TRISD1_bit; sbit LCD_D5_Direction at TRISD2_bit; sbit LCD_D6_Direction at TRISD3_bit; sbit LCD_D7_Direction at TRISD4_bit; char i; unsigned char sec, min1, hr, week_day, day, mn, year; char *txt, tnum[4]; // for some other testing char txtSec[10]; char txtMin[10]; char txtHour[10]; char txtWeekDay[10];

char txtDay[10]; char txtMn[10]; char txtYear[5]; char txtDisplay[39]; // for some testing int intSec, intMin, intHour, intWeekDay, intMn, intDay, intYear; void Write_Time() { Soft_I2C_Start(); // issue start signal // address DS1307 // start from word at address (REG0) // write 17 to hours word (24-hours mode)(REG2) (sec)* // write 2 - Monday (REG3) ,( min ) * // write 4 to date word (REG4) (hr) * // write 5 (May) to month word (REG5) (day)* // write 01 to year word (REG6) (year)*

Soft_I2C_Write(DS1307); Soft_I2C_Write(0); Soft_I2C_Write(0x22); Soft_I2C_Write(0x48); Soft_I2C_Write(0x21); Soft_I2C_Write(0x02); Soft_I2C_Write(0x13); Soft_I2C_Write(0x05); Soft_I2C_Write(0x13); Soft_I2C_Stop(); Soft_I2C_Start();

// issue stop signal // issue start signal // address DS1307 // start from word at address 0 // write 0 to REG0 (enable counting + 0 sec) // issue stop signal

Soft_I2C_Write(DS1307); Soft_I2C_Write(0); Soft_I2C_Write(0); Soft_I2C_Stop(); }

void Read_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year) { Soft_I2C_Start(); Soft_I2C_Write(DS1307); Soft_I2C_Write(0x00); Soft_I2C_Start(); Soft_I2C_Write(0xD1); *sec =Soft_I2C_Read(1); *min =Soft_I2C_Read(1);

*hr =Soft_I2C_Read(1); *week_day =Soft_I2C_Read(1); *day =Soft_I2C_Read(1); *mn =Soft_I2C_Read(1); *year =Soft_I2C_Read(0); Soft_I2C_Stop(); } void Transform_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *mn, char *year) { *sec = ((*sec & 0x70) >> 4)*10 + (*sec & 0x0F); *min = ((*min & 0xF0) >> 4)*10 + (*min & 0x0F); *hr = ((*hr & 0x30) >> 4)*10 + (*hr & 0x0F); *week_day =(*week_day & 0x07); *day = ((*day & 0xF0) >> 4)*10 + (*day & 0x0F); *mn = ((*mn & 0x10) >> 4)*10 + (*mn & 0x0F); *year = ((*year & 0xF0)>>4)*10+(*year & 0x0F); }

void Display_Time(char sec, char min, char hr, char week_day, char day, char mn, char year) { switch(week_day) { case 1: txt="Sun"; break; case 2: txt="Mon"; break; case 3: txt="Tue"; break; case 4: txt="Wed"; break; case 5: txt="Thu"; break; case 6: txt="Fri"; break; case 7: txt="Sat"; break; } Lcd_Init(); Lcd_Cmd(_LCD_CLEAR); Lcd_Cmd(_LCD_CURSOR_OFF); // Clear display // Cursor off

Lcd_Out(1,1,txt); Lcd_Chr(1, 6, (day / 10) + 48); // Print tens digit of day variable Lcd_Chr(1, 7, (day % 10) + 48); Lcd_Chr(1,8,'.'); Lcd_Chr(1, 9, (mn / 10) + 48); Lcd_Chr(1,10, (mn % 10) + 48); Lcd_Chr(1,11,'.'); Lcd_Chr(1,12, (year / 10) + 48); Lcd_Chr(1,13, (year % 10) + 48); txt = "Time"; Lcd_Out(2,1,txt); Lcd_Chr(2, 6, (hr / 10) + 48); Lcd_Chr(2, 7, (hr % 10) + 48); Lcd_Chr(2,8,':'); Lcd_Chr(2, 9, (min / 10) + 48); Lcd_Chr(2,10, (min % 10) + 48); Lcd_Chr(2,11,':'); Lcd_Chr(2,12, (sec / 10) + 48); Lcd_Chr(2,13, (sec % 10) + 48); Lcd_Cmd(_LCD_CURSOR_OFF); } void Init_Main_Simple() { ADCON1 = 0x0F; // page 268, disable analaog CMCON = 0x07; INTCON2 = 0x80; // disable pull up in port b // Print year vaiable + 8 (start from year 2008) // Print oness digit of day variable

// clears internal latches LATB = 0x03; // enable internal pull ups LATA = 0x00; LATC = 0x00; LATD = 0x00; LATE = 0x00;

// Make all outputs TRISA = 0x00; TRISB = 0x03; TRISC = 0x00; TRISD = 0x00; TRISE = 0x00; Lcd_Init(); // Initialize LCD // Clear LCD display

Lcd_Cmd(_LCD_CLEAR);

Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off

Soft_I2C_Init(); Lcd_Out(1,1,"Time & Date"); } void main() { Init_Main_Simple(); Delay_ms(100); while (1) {

// initialize I2C

Read_Time(&sec,&min1,&hr,&week_day,&day,&mn,&year); RTC(DS1307)

// read time from

Transform_Time(&sec,&min1,&hr,&week_day,&day,&mn,&year); // format date and time Display_Time(sec, min1, hr, week_day, day, mn, year); Delay_ms(1000);

} }

List of parts:
Part 2-PIC18F4550 cost 100 description

PIC18F4550 is an 8-bit microcontroller of PIC18 family. PIC18F family is based on 16-bit instruction set architecture. PIC18F4550 consists of 32 KB flash memory, 2 KB SRAM...
LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits

LCD

DS1307

(100 sar)

The DS1307 serial real-time clock (RTC) is a low power, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are Transferred serially through an I2C, bidirectional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information

3-Resistor) 10k( 2- crystals crystals ( 32K Hz( for the IC, )8M Hz( for the PIC )

2 batteries 2 -capacitors 22 F

voltages (3v for the IC and 5v for the PIC )

Experimental Results:
It Show the time and date in the LCD

Objective:
To make a real time digital clock that shows the date and time together. To understand the concept of pic microcontroller. Working on LCD and programing.

Abstract:
In this project we used pic 184550 with a help of using DS1307 which is for generating the time, choosing the mode of it like whether it's 12 or 24 and for showing the word "DTAE: YEAR/MONTH/DAY TIME: HOURS/MINITS/ SECONDS"

In the LCD lm016l which type is 2x16, we will get the output like the above DATE &TIME. Also, we used two crystals one is for the PIC and the other for the DS1307. We used three switches to adjust the time. We used one capacitor for each crystal. We provided two voltages (3v), one connected with PIC and the other with DS1307. We used five resistors each one is 10 k ohm as showing in the circuit diagram below.

Circuit diagram:

Contact:

PIC 184550 DS1307 LCD lm016l type 2x16 2 crystals ( 32K Hz for the IC, 8M Hz for the PIC ) 2 voltages (3v for the IC and 5v for the PIC ) 4 resistors of 10 k ohm( 3 for the IC , 1 for the PIC ) 3 switches 2 capacitors 22 F

Sample:

Software: mikroc Language: c ++

Hardware:

Você também pode gostar