real time digital clock report

17
Real time digital clock Prepared By Reem Hashim 09120005 Layal Khalid 09120012 Hanan Mohammad 09120037 Supervised by

Upload: noor-ahmed

Post on 04-Jan-2016

122 views

Category:

Documents


5 download

DESCRIPTION

report

TRANSCRIPT

Page 1: Real Time Digital Clock Report

Real time digital clock

Prepared By

Reem Hashim 09120005

Layal Khalid 09120012

Hanan Mohammad 09120037

Supervised by

Miss Atiya Azmi

Page 2: Real Time Digital Clock Report

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

Page 3: Real Time Digital Clock Report

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

Page 4: Real Time Digital Clock Report

Schematics of the Systems:

Figure2:Schematics of the Systems

Flowchart :

Page 5: Real Time Digital Clock Report

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];

Page 6: Real Time Digital Clock Report

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

Soft_I2C_Write(DS1307); // address DS1307

Soft_I2C_Write(0); // start from word at address (REG0)

Soft_I2C_Write(0x22); // write 17 to hours word (24-hours mode)(REG2) (sec)*

Soft_I2C_Write(0x48); // write 2 - Monday (REG3) ,( min ) *

Soft_I2C_Write(0x21); // write 4 to date word (REG4) (hr) *

Soft_I2C_Write(0x02); // write 5 (May) to month word (REG5) (day)*

Soft_I2C_Write(0x13); // write 01 to year word (REG6) (year)*

Soft_I2C_Write(0x05);

Soft_I2C_Write(0x13);

Soft_I2C_Stop(); // issue stop signal

Soft_I2C_Start(); // issue start signal

Soft_I2C_Write(DS1307); // address DS1307

Soft_I2C_Write(0); // start from word at address 0

Soft_I2C_Write(0); // write 0 to REG0 (enable counting + 0 sec)

Soft_I2C_Stop(); // issue stop signal

}

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);

Page 7: Real Time Digital Clock Report

*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); // Clear display

Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

Page 8: Real Time Digital Clock Report

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); // Print oness digit of day variable

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); // Print year vaiable + 8 (start from year 2008)

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

// clears internal latches

LATB = 0x03; // enable internal pull ups

LATA = 0x00;

LATC = 0x00;

LATD = 0x00;

LATE = 0x00;

Page 9: Real Time Digital Clock Report

// Make all outputs

TRISA = 0x00;

TRISB = 0x03;

TRISC = 0x00;

TRISD = 0x00;

TRISE = 0x00;

Lcd_Init(); // Initialize LCD

Lcd_Cmd(_LCD_CLEAR); // Clear LCD display

Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off

Soft_I2C_Init(); // initialize I2C

Lcd_Out(1,1,"Time & Date");

}

void main() {

Init_Main_Simple();

Delay_ms(100);

while (1) {

Read_Time(&sec,&min1,&hr,&week_day,&day,&mn,&year); // read time from RTC(DS1307)

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);

}

}

Page 10: Real Time Digital Clock Report

List of parts:Part cost description2-PIC18F4550 100 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 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

DS1307 (100 sar) The DS1307 serial real-time clock (RTC) is a low power,full binary-coded decimal (BCD) clock/calendarplus 56 bytes of NV SRAM. Address and data areTransferred 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 voltages (3v for the IC and 5v for the PIC )

2 -capacitors 22 F

Page 11: Real Time Digital Clock Report

Experimental Results:

It Show the time and date in the LCD

Page 12: Real Time Digital Clock Report

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"

Page 13: Real Time Digital Clock Report

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:

Page 14: Real Time Digital Clock Report

Software: mikroc

Language: c ++

Hardware: