Spread the love

Clock-Savers-Digital-Clock-Screensaver

___________________________________________________________________________________________________

  •  What is RTC ? – A real-time clock (RTC) is a computer clock (most often in the form of an integrated circuit) that keeps track of the current time. Although the term often refers to the devices in personal computersservers and embedded systems, RTCs are present in almost any electronic device which needs to keep accurate time.

 rtc interfacing with atmeg16 using i2c protocol

  • How RTC work – There are 2 clocks in a computer. One is a hardware clock known as the Real Time Clock and the other is Software Clock.
  • Real Time Clock is battery backup power clocks so that it tracks the time even while the computer is turned off, or in low power state. Basically RTC is not a physical clock but is an IC which is present on the motherboard and responsible for timing functioning of the system and system clock. Real Time Clock is responsible to make sure that all the processes occurring in the system are properly synchronized (basically this is task of system clock, but system clock is dependent on RTC, therefore RTC is indirectly responsible for interrupts, timer, task scheduling and synchronization etc.). Today many companies like Philips, ST Microelectronics, Texas Instruments manufacture RTCs. There has been a continuous development in RTC, like lowering power consumption, improving frequency stability.
  •  System Clock is maintained by the kernel of an operating system and is used to set the tasks and processes – their synchronization and scheduling, settings and managing interrupts, setting timer etc. The system clock reports seconds and microseconds since a start point from the system boot up procedure. Basically the system clock is digital signal emitter, which emits signal composed of high (1) and low (0), because all the machines and their processes understand the language of binary. 

 Kurz-vorgestellt-Mini-RTC-DS1307-Echtzeituhr-Breakoutboard-blog.simtronyx.de_-1024x768

  •  About RTC

 

  1. The RTC was introduced to PC compatibles by the IBM PC/AT in 1984, which used a Motorola MC146818 RTC. Later Dallas Semiconductor made compatible RTCs, which was often used in older personal computers, and are easily found on motherboards because of their distinctive black battery cap and silkscreened logo
  2. RTC keeps track of the second, minute, hour, day, month, and year and also is responsible for making sure all the signals sent between the devices are sent at the right intervals.
  3. Power source – RTCs often have an alternate source of power, so they can continue to keep time while the primary source of power is off or unavailable. This alternate source of power is normally a lithium battery in older systems, but some newer systems use a supercapacitor, because they are rechargeable and can be soldered. The alternate power source can also supply power to battery backed RAM.
  4. Clocks – Most RTCs use a crystal oscillator, but some use the power line frequency. In many cases the oscillator’s frequency is 32.768 kHz. This is the same frequency used inquartz clocks and watches, and for the same reasons, namely that the frequency is exactly 215 cycles per second, which is a convenient rate to use with simple binary counter circuits.
  5. Sometimes more accurate than other methods
  6. Frees the main system for time-critical tasks

 DSC06900

 

  • Applications – RTC  is used to track the system time up to date and related application

Click Here : program point of view understanding of RTC interfacing with ATmeg16

 1.Circuit Diagram of RTC interfacing with ATmega16 using DS1307

rtc interfacing with atmeg16 using ds1307

 

________________________________________________________________________________________________

 1. Program of  RTC interfacing with ATmega16 using DS1307

/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- RTC VALUE OF DS1307 IS DISPLAYED ON 
LCD USING I2C PROTOCOL OF ATMEGA16
******************************************************/

#include<avr/io.h>

#include<util/delay.h>

#define lcd PORTA

void serial_ini();
void serial_tr(unsigned char);
void serial_tr_bcd(unsigned char);

void i2c_ini();
void i2c_start();
void i2c_wr(unsigned char);
unsigned char i2c_re(unsigned char);
void i2c_stop();

void rtc_ini();
void rtc_set_t(unsigned char,unsigned char,unsigned char);
void rtc_set_d(unsigned char,unsigned char,unsigned char);
void rtc_get_t(unsigned char *,unsigned char *,unsigned char *);
void rtc_get_d(unsigned char *,unsigned char *,unsigned char *);

void cmd(unsigned char x);
void lcd_display(unsigned char x);
void lcd_ini();
void lcd_str(unsigned char *str);
void lcd_pos(int line,int pos);


int main()
   {
  
       unsigned char i,j,k,p,q,r;
       DDRA=0XFF;
       DDRB=0XFF;
       rtc_ini();
       rtc_set_t(0x19,0x45,0x30);
       rtc_set_d(0x09,0x01,0x10);
       
       serial_ini();
       lcd_ini();
       lcd_str("TIME ");
       lcd_pos(2,0);
       lcd_str("DATE ");
       while(1) 
          {
                 /* time
**************************************************************************/
               lcd_pos(1,6);
               rtc_get_t(&i,&j,&k);
               lcd_display('0'+(i>>4));
               lcd_display('0'+(i & 0x0f));
               lcd_display(':');

               lcd_display('0'+(j>>4));
               lcd_display('0'+(j & 0x0f));
               lcd_display(':');

               lcd_display('0'+(k>>4));
               lcd_display('0'+(k & 0x0f));
               _delay_ms(500);

  /* date
****************************************************************************/

              lcd_pos(2,6);
              rtc_get_d(&p,&q,&r);
              lcd_display('0'+(r>>4));
              lcd_display('0'+(r & 0x0f));
              lcd_display(':');

              lcd_display('0'+(q>>4));
              lcd_display('0'+(q & 0x0f));
              lcd_display(':');

              lcd_display('0'+(p>>4));
              lcd_display('0'+(p & 0x0f));
              _delay_ms(500);

         }
       return 0;
   }

void serial_ini()
   {
       UCSRB=(1<<TXEN);
       UCSRC=(1<<UCSZ1)|(1<<UCSZ0)|(1<<URSEL);
       UBRRL=0X33;
    }
    
void serial_tr(unsigned char x)
   {
       while(!(UCSRA & (1<<UDRE)));
       UDR= x; 
       while(TXC ==0);
   }

void serial_tr_bcd(unsigned char x)
   {
       serial_tr('0'+(x>>4));
       serial_tr('0'+(x & 0x0f));
   }

void i2c_ini()
   {
       TWSR=0X00;
       TWBR=0X47;
       TWCR=0X04;
   }

void i2c_start()
  {
      TWCR=(1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
      while((TWCR &(1<<TWINT))==0);
  }

void i2c_wr(unsigned char x)
  {
     TWDR=x;
     TWCR=(1<<TWINT)|(1<<TWEN);
     while((TWCR & (1<<TWINT))==0);

  }

unsigned char i2c_re(unsigned char x)
   {
       TWCR=(1<<TWINT)|(1<<TWEN)|(x<<TWEA);
       while((TWCR &(1<<TWINT))==0);
       return TWDR;
   }

void i2c_stop()
   {
       TWCR=(1<<TWINT)|(1<<TWEN)|(1<<TWSTO);
       for(int i=0;i<200;i++);
   }

void rtc_ini()
   {
      i2c_ini();
      i2c_start();
      i2c_wr(0xd0);   // address DS1307 for write
      i2c_wr(0x07);  //set register pointer to 7
      i2c_wr(0x00);  //set value of location 7 to 0
      i2c_stop();  // transmit stop condition
   }

void rtc_set_t(unsigned char h,unsigned char m,unsigned char s)
   {
       i2c_start();
       i2c_wr(0xd0);     // address DS1307 for write
       i2c_wr(0);        //set register pointer to 0
       i2c_wr(s);
       i2c_wr(m);
       i2c_wr(h);
       i2c_stop();
   }

void rtc_set_d(unsigned char y,unsigned char m,unsigned char d)
   {
       i2c_start();
       i2c_wr(0xd0);     // address DS1307 for write
       i2c_wr(4);        //set register pointer to 4
       i2c_wr(d);
       i2c_wr(m);
       i2c_wr(y);
       i2c_stop(); 
   }

void rtc_get_t(unsigned char *h,unsigned char *m,unsigned char *s)
   {
       i2c_start();
       i2c_wr(0xd0);     // address DS1307 for write
       i2c_wr(0);        //set register pointer to 0
       i2c_stop();

       i2c_start();
       i2c_wr(0xd1);     // address DS1307 for read
       *s=i2c_re(1);     //read sec ,read ack
       *m=i2c_re(1);     //read min ,read ack
       *h=i2c_re(0);     //read hour ,read nack
       i2c_stop();
   }


void rtc_get_d(unsigned char *y,unsigned char *m,unsigned char *d)
    {
        i2c_start();
        i2c_wr(0xd1);     // address DS1307 for write
        i2c_wr(0);        //set register pointer to 4
        i2c_stop();


        i2c_start();
        i2c_wr(0xd1);     // address DS1307 for read
        *d=i2c_re(1);     //read day ,read ack
        *m=i2c_re(1);     //read month ,read ack
        *y=i2c_re(0);     //read year ,read nack
        i2c_stop();
    }

void cmd(unsigned char x)
   {
       lcd=x;
       PORTB=(0<<0);
       PORTB=(0<<1);
       PORTB=(1<<2);
       _delay_ms(10);
       PORTB=(0<<2);

   }

void lcd_display(unsigned char x)
   {
      lcd=x;
      PORTB=(1<<0);
      PORTB=(0<<1)|(1<<0);
      PORTB=(1<<2)|(0<<1)|(1<<0);
      _delay_ms(20);
      PORTB=(0<<2)|(0<<1)|(1<<0);
   }

void lcd_ini()
   {
       cmd(0x38);
       cmd(0x0e);
       cmd(0x01);
       cmd(0x06);
       cmd(0x80);
   }

void lcd_str(unsigned char *str)
   {
        while(*str!='\0')
          {
               lcd_display(*str);
               str++;
           }
    }

void lcd_pos(int line,int pos)
    {
        if(line==1)
            cmd(0x80+pos);
        else if(line==2)
            cmd(0xc0+pos);
    }

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)

download (1)

Content for the tab VIDEO