Professional Documents
Culture Documents
Technology Islamabad
Microprocessor and Interfacing
Lab Report 12
Submitted By:
Omer Zamir
BET-084
Mujtaba Habib
096
Submitted To:
Dr. Omer Ahmed
Submission Date:
FA13FA13-BET-
// to get the current time and date. The accuracy of the RTC depends upon
the
// accuracy of the crystal oscillator it is clocked with.
//
//
Task1:
date on RTC
//
// Task2:
LCD
******************************************************************************
**/
#include <avr/io.h>
#include <avr/interrupt.h>
PORTC
#define LCD_CTRL_DDR
DDRC
#define RS
PC5
#define RW
PC6
#define En
PC7
#define LCD_DATA_PORT
PORTD
#define LCD_DATA_DDR
#define LCD_CLEAR
DDRD
0x01
#define LCD_HOME
0x02
#include "LCD.h"
/***************************************************************/
#define DATE_REG
#define MONTH_REG
#define YEAR_REG
0x06
#define DOW_REG
#define HOUR_REG
0x02
/*
unsigned char date = 26;
unsigned char month = 11;
unsigned char year = 16;
// Main program
//
int main(void)
{
unsigned char date = 26;
unsigned char month = 11;
unsigned char year = 16;
system_init();
_delay_ms(200);
//LCD_display_str("Initializatin!!!");
while(1)
{
// Infinite loop; define here the
LCD_display_str("DATE ");
LCD_display_BCD(dec2bcd(date));
LCD_display_str(":");
LCD_display_BCD(dec2bcd(month));
LCD_display_str(":");
LCD_display_BCD(dec2bcd(year));
LCD_SendCommand(LCD_NEXT_LINE);
LCD_display_str("TIME ");
LCD_display_BCD(dec2bcd(hour));
LCD_display_str(":");
LCD_display_BCD(dec2bcd(minute));
LCD_display_str(":");
LCD_display_BCD(dec2bcd(second));
LCD_SendCommand(LCD_HOME);
DS1307_getDate(&date,&month,&year);
DS1307_getTime(&hour,&minute,&second);
int system_init(void)
{
LCD_Initialize();
i2c_init();
return(0);
i2c_write(DATE_REG);
date registor
i2c_write(dec2bcd(date));
i2c_write(dec2bcd(month));
i2c_write(dec2bcd(year));
i2c_stop();
return(0);
}
int DS1307_getDate(unsigned char * date, unsigned char * month,
unsigned char * year)
{
//read date
i2c_start_wait(DS1307_ADDR | I2C_WRITE);
i2c_write(DATE_REG);
i2c_stop();
i2c_start_wait(DS1307_ADDR | I2C_READ);
*date = bcd2dec(i2c_readAck());
*month = bcd2dec(i2c_readAck());
*year = bcd2dec(i2c_readNak());
i2c_stop();
return(0);
}
i2c_write(SECOND_REG);
date registor
i2c_write(dec2bcd(second));
i2c_write(dec2bcd(minute));
i2c_write(dec2bcd(hour));
i2c_stop();
return(0);
}
int DS1307_getTime(unsigned char * hour, unsigned char * minute, unsigned
char * second)
{
i2c_start_wait(DS1307_ADDR | I2C_WRITE);
i2c_write(SECOND_REG);
i2c_stop();
i2c_start_wait(DS1307_ADDR | I2C_READ);
*second = bcd2dec(i2c_readAck());
*minute = bcd2dec(i2c_readAck());
*hour = bcd2dec(i2c_readNak());
i2c_stop();
return(0);
}
Proteus Simulation: