Presentation is loading. Please wait.

Presentation is loading. Please wait.

As a part of ALA in the subject of MCI (2151001) subject faculty:Hiren Patel Sir Presentation on rtc interfacing with atmega32 using ds1307 By:selva kumar.r.

Similar presentations


Presentation on theme: "As a part of ALA in the subject of MCI (2151001) subject faculty:Hiren Patel Sir Presentation on rtc interfacing with atmega32 using ds1307 By:selva kumar.r."— Presentation transcript:

1 As a part of ALA in the subject of MCI (2151001) subject faculty:Hiren Patel Sir Presentation on rtc interfacing with atmega32 using ds1307 By:selva kumar.r ec dept sem 5: enroll no:131080111005

2 Contents inside:-  Introduction  Internal registers  Simple RTC module  Reading internal register in RTC using codes  DS 1307 with Atmega32  Schematic diagram of the interfacing

3 Introduction  Real Time Clocks, as the name suggests are clock modules. They are available as integrated circuits (ICs) and manages timing like a clock. Some RTC ICs also manages date like a calendar. The main advantage is that they have a system of battery backup which keeps the clock/ca lender running even in case of power failure. A very small current is required for keeping the RTC alive. This in most case is provided by a miniature 3v lithium coin cell. So even if the embedded system with RTC is powered off the RTC module is up and running by the backup cell. his same technique is used in PC timing also. If you have opened your computer case you will notice a small coin cell in the mother board.

4  The DS1307 is a low-power clock/calendar with 56 bytes of battery-backed SRAM. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The date at the end of the month is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The DS1307 operates as a slave device on the I2C bus.

5 Internal Registers ADDRESSBIT7BIT6BIT5BIT4BIT3BIT2BIT1BIT0FUNCTIONRANGE 00H CH10 SECONDSSECOND 00-59 01H 010 MINUTESMINUTES 00-59 02H 0 1210HR HOUR 1-12+AM/PM OR 00-23 24am/pm 03H 00000DAY 01-07 04H 0010 DATEDATE 01-31 05H 00010MONTHMONTH 01-12 06H 10 YEARYEAR 00-99 07H TO KEEP THINGS SIMPLE I HAVE SKIPPED THE CONTROL REGISTER THIS IS USED FOR SQUARE WAVE GENERATION ON PIN7 08-3FH 56 BYTE RAM00h-FFh

6 Simple RTC module  The DS1307 require an 32.768KHz crystal, a 3v lithium battery and 2 pull up registers to function. So I will make a small PCB that will hold all these. The image of module is shown below. The module can be connected to development boards using female-female burg wires.DS130732.768KHz crystaldevelopment boardsfemale-female burg wires

7 Code to read internal register in RTC address : Address of the register data: value of register is copied to this. Returns: 0= Failure 1= Success ***************************************************/ uint8_t DS1307Read(uint8_t address,uint8_t *data) /*************************************************** Function To Write Internal Registers of DS1307 --------------------------------------------- address : Address of the register data: value to write. Returns: 0= Failure 1= Success ***************************************************/ uint8_t DS1307Write(uint8_t address,uint8_t data)

8 RTC DS(1307) interfacing with Atmega 32  # include  void init_i2c()  {  TWSR = 0X00;  TWBR = 0X47;  TWCR = (1<<TWEN);  }

9  unsigned char read_i2c()  {  TWCR = (1<<TWINT)|(1<<TWEN);  while(!(TWCR & (1<<TWINT)));  return TWDR;  }  void write_i2c(unsigned char ch)  {  TWDR = ch;  TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA);  while(!(TWCR&(1<<TWINT)));  }

10  void start()  {  TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);  while((TWCR &(1<<TWINT))==0);  }  void stop()  {  TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);  _delay_ms(1);  }

11  void rtc_write(char dev_addr,char dev_loc,char dev_data)  {  start();  write_i2c(dev_addr);  write_i2c(dev_loc);  write_i2c(dev_data);  stop();  _delay_ms(10);  }

12  unsigned char rtc_read(char dev_addr,char dev_loc)  {  char ch;  start();  write_i2c(dev_addr);  write_i2c(dev_loc);  start();  write_i2c(dev_addr|0x01);  ch = read_i2c();  stop();  return ch;  }

13  void tx( unsigned char data )  {  while ( !(UCSRA & (1<<UDRE)) ); // wait until UDR is empty  UDR = data;  }  char rx()  {  while ( !(UCSRA & (1<<RXC)) ); // wait until UDR is empty  return UDR;  }

14  void init_serial()  {  UCSRB = (1<<RXEN)|(1<<TXEN);  UCSRC = (1<<UCSZ1)|(1<<UCSZ0);  UBRRL = 51;  }  void str_serial(char *str)  {  while(*str)  {  tx(*str++);  _delay_ms(1);  }

15  void disp_time_date()  {  char ch;  tx(254);  tx(128);  str_serial("Time: ");  ch = rtc_read(0xd0, 0x02);  tx(ch/16+48);  tx(ch%16+48);  tx('-');

16  ch = rtc_read(0xd0, 0x01);  tx(ch/16+48);  tx(ch%16+48);  tx('-');  ch = rtc_read(0xd0, 0x00);  tx(ch/16+48);  tx(ch%16+48);  tx(254);  tx(192);

17  str_serial("Date: ");  ch = rtc_read(0xd0, 0x04);  tx(ch/16+48);  tx(ch%16+48);  tx('-');  ch = rtc_read(0xd0, 0x05);  tx(ch/16+48);  tx(ch%16+48);  tx('-');

18  ch = rtc_read(0xd0, 0x06);  tx(ch/16+48);  tx(ch%16+48);  }

19  int main()  {  DDRC =0XFF; DDRD =0XFF;  init_i2c();  init_serial();  rtc_write(0xd0,0x00,0x00);  rtc_write(0xd0,0x01,0x27);  rtc_write(0xd0,0x02,0x08);  rtc_write(0xd0,0x04,0x08);  rtc_write(0xd0,0x05,0x09);  rtc_write(0xd0,0x06,0x13);  _delay_ms(10000);

20  while(1)  {  disp_time_date();  }

21 Schematic of the interfacing T h e E n d...


Download ppt "As a part of ALA in the subject of MCI (2151001) subject faculty:Hiren Patel Sir Presentation on rtc interfacing with atmega32 using ds1307 By:selva kumar.r."

Similar presentations


Ads by Google