• 1

    ..

  • 2

    ...

  • 3

    ...

Tuesday 25 February 2014

DS1307 RTC AVR atmega16 - Digital Clock

        Here is a simple digital watch which displays time, date & day in 16x2 lcd. DS1307 RTC is used for the time & date watch and AVR Atmega16 (8/32/64) is used as the display driver. It reads RTC time, date, day from ds1307 throught I2C bus and process it for displaying and displays it in the LCD.


Click here to view our DS1307 tutorial & header file for AVR GCC.
Circuit diagram  for DS1307 RTC Digital Watch with AVR is  as follows: 
 
Figure 1 - Circuit diagram
Connect a BUZZER  at pin PD6 if needed.
  
                To initialize DS1307 with the required time use this program first. It sets time as 12:45:32 & date as 24 Feb 14, Tuesday, by default. If you need to change, do it in BCD format.
 
/*************   WRITE TIME IN DS1307 ***********************/
#ifndef BIT
#define BIT(x)    _BV(x)
#endif

#ifndef SETBIT
#define SETBIT(x,b)     x|=_BV(b);
#endif

#ifndef CLEARBIT
#define CLEARBIT(x,b)   x&=~_BV(b);
#endif

#ifndef TOGGLEBIT
#define TOGGLEBIT(x,b) x^=_BV(b);
#endif

#ifndef CHECKBIT
#define CHECKBIT(x,b)   (x & _BV(b))
#endif

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/sleep.h>

/* waits (pauses) for ms milliseconds */
void WaitMs(unsigned int ms)
{
      unsigned int m;

      for(m=0;m<=ms/10;m++)
      {
            _delay_ms(10);
      }
}
#define nop() asm __volatile__ ("nop\t\n")


#include "lcd.c"
#include "ds1307.h"

#define M(x) ( (x&0xF0)>>4 | 0x30 )
#define L(x) ( (x&0x0F) | 0x30 )

unsigned char h,m,s; //,pwrd=1;  //,aP;
#define ReadTime() DSReadTime(&h,&m,&s)
#define WriteTime() DSWriteTime(h,m,s)
unsigned char dd,mm,yy,dy;
#define ReadDate() DSReadDate(&dd,&mm,&yy)
#define WriteDate() DSWriteDate(dd,mm,yy)

                    //01 34 678
char T[9];  //="hh:mm:ss*";
char D[11]; //="dd/mm/yy";

#define disptim() LCD_putsXY(4,0,T)
#define dispd() LCD_putsXY(0,1,D)

void upt()
{
T[0]=M(h);
T[1]=L(h);
T[3]=M(m);
T[4]=L(m);
T[6]=M(s);
T[7]=L(s);
//if(aP)          LCD_putc('P');    else        LCD_putc('A');   
}

void upd()
{
D[0]=M(dd);
D[1]=L(dd);
D[3]=M(mm);
D[4]=L(mm);
 D[8]=M(yy);      D[9]=L(yy);
//if(aP)          LCD_putc('P');    else        LCD_putc('A');   
}


int main()
{
 D[2]='/';  D[5]='/'; D[6]='2'; D[7]='0';
 T[2]=':';  T[5]=':';
 DDRB=0x00;
 PORTB=0xFE;  // sw_init();
 LCD_init(COFF);
 LCD_clear();
 LCD_putsPXY(0,0,"WeLcOmE....");
 buzz(); buzz();

 DSinit();
#ifdef MODE_12HR
#else
 T[8]='\0';//24hour mode  default 24hour mode
#endif

 _delay_ms(50);

//for write time
WaitMs(900);
h=0x12; m=0x45; s=0x32; //time = 12:45:32
dd=0x24; mm=0x02; yy=0x14; dy=0x02;  //date is 24 feb 2014 Tuesday
WriteTime();
WriteDate();
DSWriteDay(dy);
WaitMs(900);

ReadTime();
ReadDate();
DSReadDay(&dy);
upt();upd();
disptim();
dispd();

while(1)
      {
            _delay_us(50);                     
            sleep_mode();    
            nop();
      }
 return 0;
}


THE PROGRAM FOR CLOCK IS AS FOLLOWS…….
                The DS1307 is initialized to produce 1Hz at SOUT pin (pin7). This pin is connected to INT0 of ATMEGA to generate an interrupt. The ISR is coded to read time, date, day from DS1307 & display it in LCD. After ISR execution, it enter the main while loop, which makes the CPU to enter Sleep mode. This is implemented to reduce power consumption.

/*********MACRO's DEFINITION**************/
#ifndef BIT
#define BIT(x)  _BV(x)
#endif

#ifndef SETBIT
#define SETBIT(x,b) x|=_BV(b);
#endif

#ifndef CLEARBIT
#define CLEARBIT(x,b)      x&=~_BV(b);
#endif

#ifndef TOGGLEBIT
#define TOGGLEBIT(x,b)     x^=_BV(b);
#endif

#ifndef CHECKBIT
#define CHECKBIT(x,b)      (x & _BV(b))
#endif
/*******************************************************************/

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/sleep.h>

/* waits (pauses) for ms milliseconds */
void WaitMs(unsigned int ms)
{
     unsigned int m;

     for(m=0;m<=ms/10;m++)
     {
           _delay_ms(10);
     }
}
#define nop() asm __volatile__ ("nop\t\n")


#include "lcd.c"
#include "ds1307.h"

#define M(x) ( (x&0xF0)>>4 | 0x30 )
#define L(x) ( (x&0x0F) | 0x30 )

unsigned char h,m,s; //,pwrd=1;  //,aP;
#define ReadTime() DSReadTime(&h,&m,&s)
#define WriteTime() DSWriteTime(h,m,s)
unsigned char dd,mm,yy,dy;
#define ReadDate() DSReadDate(&dd,&mm,&yy)
#define WriteDate() DSWriteDate(dd,mm,yy)

                  //01 34 678
char T[9]; //="hh:mm:ss*";
char D[11];     //="dd/mm/yy";

#define disptim() LCD_putsXY(4,0,T)
#define dispd() LCD_putsXY(0,1,D)

void upt()
{
T[0]=M(h);
T[1]=L(h);
T[3]=M(m);
T[4]=L(m);
T[6]=M(s);
T[7]=L(s);
//if(aP)        LCD_putc('P');  else       LCD_putc('A'); 
}

void upd()
{
D[0]=M(dd);
D[1]=L(dd);
D[3]=M(mm);
D[4]=L(mm);    
 D[8]=M(yy);    D[9]=L(yy);
//if(aP)        LCD_putc('P');  else       LCD_putc('A'); 
}

void buzz()
{
     SETBIT(PORTD,6)
     _delay_ms(350);
     CLEARBIT(PORTD,6)
}

ISR(INT0_vect)
{//1 int0
     ReadTime();
     ReadDate();
     DSReadDay(&dy);
#ifdef MODE_12HR
//12hour mode
     if( (h&0x20)==0x20)
           { aP=1; T[8]='P';}
     else
           { aP=0; T[8]='A';}
     h=h&0x1F;
#else
  h=h&0x3F; //24hour mode  default 24hour mode
#endif

     upt();upd();
     disptim();
     dispd();
    
     LCD_puts("  ");
     dy=dy & 0x07;
     if(dy==0x01) LCD_puts("SUN");
     else if(dy==0x02) LCD_puts("MON");
     else if(dy==0x03) LCD_puts("TUE");
     else if(dy==0x04) LCD_puts("WED");
     else if(dy==0x05) LCD_puts("THU");
     else if(dy==0x06) LCD_puts("FRI");
     else if(dy==0x07) LCD_puts("SAT");
}

int main()
{
 D[2]='/'; D[5]='/'; D[6]='2'; D[7]='0';
 T[2]=':'; T[5]=':';
 DDRB=0x00;
 PORTB=0xFE;  // sw_init();
 LCD_init(COFF);
 LCD_clear();
 LCD_puts2XY(4,0,"WeLcOmE...");
 LCD_puts2XY(0,1,"www.elecdude.com");
 buzz(); buzz();

 DSinit();
#ifdef MODE_12HR
#else
 T[8]='\0';//24hour mode  default 24hour mode
#endif

 _delay_ms(50);
DDRD = (1<<7) | (1<<6) | (0<<2);
 SETBIT(PORTD,2)
 SETBIT(GICR,INT0)
 MCUCR|= ( (1<<ISC01)|(0<<ISC00) );
   //ext int0 @falling edge(10)           
 set_sleep_mode(SLEEP_MODE_IDLE);
 SETBIT(TIMSK,OCIE0) //T0 compate int
 OCR0=0x15;
 TCNT0=0x00;
 TCCR0=0x00;
LCD_clear();
 WaitMs(900);
 sei();
 while(1)
     {
           _delay_us(50);                 
           sleep_mode();  
           nop();
     }
 return 0;
}

OUTPUT SNAPSHOT:

digital watch: elecdude.com


If you want to add beep every hour, just add in ISR.
Declare a variable hpre=0x00;
CODE:
if(hpre!=h)
     { buzz(); hpre=h;}

Like this you can add a pre-defined alarm at required time.


If you've any queries with this, logon to forum.elecdude.info & post it.
Thankyou.



Here is a simple digital watch which displays time, date & day in 16x2 lcd. DS1307 RTC is used for the time & date watch and AVR Atmega16 (8/32/64) is used as the display driver. It reads RTC time, date, day from ds1307 throught I2C bus and process it for displaying and displays it in the LCD.

Digital Watch


Click here to view our DS1307 tutorial & header file for AVR GCC.

Circuit diagram  for DS1307 RTC Digital Watch with AVR is  as follows:
 
Figure 1 - Circuit diagram
Connect a BUZZER  at pin PD6 if needed.
 
                To initialize DS1307 with the required time use this program first. It sets time as 12:45:32 & date as 24 Feb 14, Tuesday, by default. If you need to change, do it in BCD format.
/*************   WRITE TIME IN DS1307 ***********************/
#ifndef BIT
#define BIT(x)    _BV(x)

Monday 24 February 2014

ISRO Recruitment 2014 – Apply Online for 102 ISRO Scientist/ Engineer – SC Posts

Indian Space Research Organization (ISRO) invites applications for the recruitment of Scientist/ Engineer – SC Posts. Eligible candidates can apply online from 20-02-2014 to 13-03-2014.


 

Total No of Posts: 102


Name of the Post
:


Code

Post Name

No. of Vacancies

BE001

Scientist/Engineer SC - Electronics

35

BE002

Scientist/Engineer SC - Mechanical

50

BE003

Scientist/Engineer SC - Computer Science

17

(click on post to start applying online)

Age Limit: Candidates age should be 35 years as on 13-03-2014. Age Relaxation is applicable for Ex-Serviceman and Persons with Disabilities.

 

Educational Qualification: Candidates should have BE/ B.Tech or equivalent in 1st Class with an aggregate minimum of 65% (average of all semesters for which results are available).

 

Selection Procedure: Candidates are selected based on written test, interview.

 

Application Fee: Candidates need to pay the fee of Rs.100/- for each application. After registration of the online application, candidates can down load the payment Challan and pay the fee at State bank of India between 20-02-2014 and 14-03-2014. Upon remittance of the application fee, one copy of the Challan form will be retained by the State Bank (Bank copy) and remaining two Challan parts, candidate has to send one part of the Challan form (ISRO copy) and remaining one copy of Challan form shall be retained by the candidate for future reference and no fee for Women, SC, ST, Ex-serviceman (EX) and persons with disabilities (PWD) candidates.

 

How to Apply: Eligible candidates can apply online from the website http://www.isac.gov.in from 20-02-2014 to 13-03-2014. After registration of application on-line, the candidates have to take the print out of application and send it along with Challan (ISRO copy) and all relevant certificates to the 'Head, P & GA (ICRB), ISRO Headquarters, Antariksh Bhavan, New BEL Road, Bangalore – 560094' by post superscribing on the envelope "ICRB – RECRUITMENT OF SCIENTIST/ENGINEER" within 7 days of filing of application (on or before 21-03-2014). The remaining copy of registration conformation form (applicant copy) shall be retained by the candidate for future references.

 

Important Dates:

Starting Date of Online Application: 20-02-2014.

Last Date for Submission of Application: 13-03-2014.

Starting Date for Fee Payment: 20-02-2014.

Last Date for Fee Payment: 14-03-2014.

Last Date for Receipt of Application: Within 7 days of filing of application (on or before 21-03-2014).

Date of Written Exam: 26-04-2014.

 

Click here to view Recruitment Ad and Online Application Form.

Search Here...