Tuesday 8 October 2013

DIGITAL CALENDER USING ATmega16

Introduction :-
                      In this project we use ATmega16 controller and a 16x2 alphanumeric LCD. Program is loaded in the ATmega16 and the digital calender is ready to run. This calender is starts from 2013 and ends in 2100. You can reduce delay for seeing results quickly.


Lcd Interfacing :-
                              see.. LCD INTERFACING WITH ATmega16 IN 4-BIT MODE


ATmega16 :-
                       


Components required :-
  1. 10k ohm registance
  2. 10k ohm variable registance
  3. 8 MHZ crystal oscilltor
  4. 16x2 LCD
  5. ATmega16 IC
  6. 12v battery 
  7. Toggle button
  8. 7805 IC
  9. 330 ohm resistance
  10. 1N4007 diode
  11. 1000uf capacitor
  12. Green LED

Circuit Diagram :-




In  4-bit mode ground the first 4 data pins of LCD means pin 7-11. make the connections as shown above.


Code (compiled in CVAVR) :-  

                                                (see.. CVAVR TUTORIAL (CODE VISION AVR))

Note :- In CVAVR program window delete all the lines and paste the code given below. because there are so much unnecessary lines.

-----------------------------------------------------------------------------------------------------------------------

#include <mega16.h>
#include <delay.h>
#include <stdlib.h>

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>

void main(void)
{
 int i=0,y,m,d,k=0;
 char c[20];
 
// LCD module initialization
  lcd_init(16);
  lcd_gotoxy(2,0);
  lcd_putchar('/');   
   lcd_gotoxy(5,0);
  lcd_putchar('/');   
 
  
while (1)
    {  
      for(y=2013;y<2100;y++)
        { 
        lcd_gotoxy(6,0);
        itoa(y,c);
        lcd_puts(c);                
      
         for(m=1;m<=12;m++)
           {
              if(m<=9)    
                    {
                     lcd_gotoxy(3,0);
                     itoa(i,c);
                     lcd_puts(c);
                     itoa(m,c);  
                     lcd_gotoxy(4,0);
                     lcd_puts(c); 
                    }
                 else
                   {    
                     itoa(m,c);  
                     lcd_gotoxy(3,0);
                     lcd_puts(c); 
                   }
             if(m<=7&&m%2==1)
              {
                for(d=1;d<=31;d++)
                { 
                 k++;
                   lcd_gotoxy(0,1);
                    if(k==1)
                    lcd_putsf("TUESDAY  ");

                    if(k==2)
                    lcd_putsf("WEDNESDAY");

                    if(k==3)
                    lcd_putsf("THRUSDAY ");

                    if(k==4)
                    lcd_putsf("FRIDAY   ");

                    if(k==5)
                    lcd_putsf("SATURDAY ");

                    if(k==6)
                    lcd_putsf("SUNDAY   ");

                    if(k==7)
                    {
                    lcd_putsf("MONDAY   ");
                    k=0;
                    }
                  if(d<=9)    
                  {
                   lcd_gotoxy(0,0);
                   itoa(i,c);
                   lcd_puts(c);
                   itoa(d,c);  
                   lcd_gotoxy(1,0);
                   lcd_puts(c);    
                   delay_ms(1000);
                   
                  
                  }
                 else
                 {    
                  itoa(d,c);  
                  lcd_gotoxy(0,0);
                  lcd_puts(c);  
                  delay_ms(1000);
                 }  
                       
               }    
              }
           else if(m>=8&&m%2==0)
              {                
              for(d=1;d<=31;d++)
                 { 
                  k++;
                   lcd_gotoxy(0,1);
                    if(k==1)
                    lcd_putsf("TUESDAY  ");

                    if(k==2)
                    lcd_putsf("WEDNESDAY");

                    if(k==3)
                    lcd_putsf("THRUSDAY ");

                    if(k==4)
                    lcd_putsf("FRIDAY   ");

                    if(k==5)
                    lcd_putsf("SATURDAY ");

                    if(k==6)
                    lcd_putsf("SUNDAY   ");

                    if(k==7)
                    {
                    lcd_putsf("MONDAY   ");
                    k=0;
                    }
                   if(d<=9)    
                    {
                     lcd_gotoxy(0,0);
                     itoa(i,c);
                     lcd_puts(c);
                     itoa(d,c);  
                     lcd_gotoxy(1,0);
                     lcd_puts(c); 
                     delay_ms(1000);
                    }
                 else
                   {    
                     itoa(d,c);  
                     lcd_gotoxy(0,0);
                     lcd_puts(c); 
                     delay_ms(1000);
                   } 
                    
                 }
              }
                 
              
              
             else if(m==2&&y%4==0)
              {
               for(d=1;d<=29;d++)
                 { 
                  k++;
                   lcd_gotoxy(0,1);
                    if(k==1)
                    lcd_putsf("TUESDAY  ");

                    if(k==2)
                    lcd_putsf("WEDNESDAY");

                    if(k==3)
                    lcd_putsf("THRUSDAY ");

                    if(k==4)
                    lcd_putsf("FRIDAY   ");

                    if(k==5)
                    lcd_putsf("SATURDAY ");

                    if(k==6)
                    lcd_putsf("SUNDAY   ");

                    if(k==7)
                    {
                    lcd_putsf("MONDAY   ");
                    k=0;
                    }      
                   if(d<=9)    
                    {
                     lcd_gotoxy(0,0);
                     itoa(i,c);
                     lcd_puts(c);
                     itoa(d,c);  
                     lcd_gotoxy(1,0);
                     lcd_puts(c); 
                     delay_ms(1000);
                    }
                 else
                   {    
                     itoa(d,c);  
                     lcd_gotoxy(0,0);
                     lcd_puts(c); 
                     delay_ms(1000);
                   } 
                   
                 }
              
              }               
            else if(m==2&&y%4!=0)
              {
              for(d=1;d<29;d++)
                 { 
                  k++;
                   lcd_gotoxy(0,1);
                    if(k==1)
                    lcd_putsf("TUESDAY  ");

                    if(k==2)
                    lcd_putsf("WEDNESDAY");

                    if(k==3)
                    lcd_putsf("THRUSDAY ");

                    if(k==4)
                    lcd_putsf("FRIDAY   ");

                    if(k==5)
                    lcd_putsf("SATURDAY ");

                    if(k==6)
                    lcd_putsf("SUNDAY   ");

                    if(k==7)
                    {
                    lcd_putsf("MONDAY   ");
                    k=0;
                    }       
                   if(d<=9)    
                    {
                     lcd_gotoxy(0,0);
                     itoa(i,c);
                     lcd_puts(c);
                     itoa(d,c);  
                     lcd_gotoxy(1,0);
                     lcd_puts(c); 
                     delay_ms(1000);
                    }
                 else
                   {    
                     itoa(d,c);  
                     lcd_gotoxy(0,0);
                     lcd_puts(c); 
                     delay_ms(1000);
                   } 
                  
                   }  
                   }                   
           else
              {
                                 
              for(d=1;d<=30;d++)
                 { 
                   k++;
                   lcd_gotoxy(0,1);
                    if(k==1)
                    lcd_putsf("TUESDAY  ");

                    if(k==2)
                    lcd_putsf("WEDNESDAY");

                    if(k==3)
                    lcd_putsf("THRUSDAY ");

                    if(k==4)
                    lcd_putsf("FRIDAY   ");

                    if(k==5)
                    lcd_putsf("SATURDAY ");

                    if(k==6)
                    lcd_putsf("SUNDAY   ");

                    if(k==7)
                    {
                    lcd_putsf("MONDAY   ");
                    k=0;
                    }
                   if(d<=9)    
                    {
                     lcd_gotoxy(0,0);
                     itoa(i,c);
                     lcd_puts(c);
                     itoa(d,c);  
                     lcd_gotoxy(1,0);
                     lcd_puts(c); 
                     delay_ms(1000);
                    }
                 else
                   {    
                     itoa(d,c);  
                     lcd_gotoxy(0,0);
                     lcd_puts(c); 
                     delay_ms(1000);
                   } 
                    
                 }
              }
             
           }
        } 
       
    }
      
-----------------------------------------------------------------------------------------------------------------------

Proteus simulation:-



Monday 7 October 2013

DIGITAL CLOCK USING ATmega16

Introduction :-
                      In this project we use ATmega16 controller and a 16x2 alphanumeric LCD. Program is loaded in the ATmega16 and the digital clock is ready to run.


Lcd Interfacing :-
                              see.. LCD INTERFACING WITH ATmega16 IN 4-BIT MODE


ATmega16 :-
                       


Components required :-
  1. 10k ohm registance
  2. 10k ohm variable registance
  3. 8 MHZ crystal oscilltor
  4. 16x2 LCD
  5. ATmega16 IC
  6. 12v battery 
  7. Toggle button
  8. 7805 IC
  9. 330 ohm resistance
  10. 1N4007 diode
  11. 1000uf capacitor
  12. Green LED

Circuit Diagram :-




In  4-bit mode ground the first 4 data pins of LCD means pin 7-11. make the connections as shown above.


Code (compiled in CVAVR) :-  

                                                (see.. CVAVR TUTORIAL (CODE VISION AVR))

Note :- In CVAVR program window delete all the lines and paste the code given below. because there are so much unnecessary lines.

-----------------------------------------------------------------------------------------------------------------------

#include <mega16.h>
#include <delay.h>
#include <stdlib.h>

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>

void main(void)
{
    int h,m,s,i=0;
    char a[20];


// LCD module initialization
   lcd_init(16);

while (1)
   { 
              lcd_gotoxy(0,0);
              itoa(i,a);
              lcd_puts(a);
              lcd_gotoxy(1,0);
              lcd_puts(a);
              lcd_gotoxy(2,0);
              lcd_putchar(':');
              lcd_gotoxy(3,0);
              lcd_puts(a);
              lcd_gotoxy(4,0);
              lcd_puts(a);
              lcd_gotoxy(5,0);
              lcd_putchar(':');
              lcd_gotoxy(6,0);
              lcd_puts(a);
              lcd_gotoxy(7,0);
              lcd_puts(a);


     
      for(h=0;h<=23;h++)
      {   
       
                  if(h>=12)
                  {
                   lcd_gotoxy(9,0);
                   lcd_putsf("PM"); 
                   if(h>=12&&h<13)
                   {  
                    lcd_gotoxy(0,0);
                    itoa(h,a);
                    lcd_puts(a);
                   }
                   if(h>=13)
                   {
                    h=h-12; 
                     if(h<=9)     
                       { 
                        lcd_gotoxy(0,0);
                        itoa(i,a);
                        lcd_puts(a);
                        lcd_gotoxy(1,0);
                        itoa(h,a);
                        lcd_puts(a);
                       }
                    else
                      {
                       lcd_gotoxy(0,0);
                       itoa(h,a);
                       lcd_puts(a);
                      }
                    h=h+12;    
                   }      
                  }        
                  else
                  {
                  lcd_gotoxy(9,0);
                  lcd_putsf("AM");
                   if(h<=9)     
                    { 
                     lcd_gotoxy(0,0);
                     itoa(i,a);
                     lcd_puts(a);
                     lcd_gotoxy(1,0);
                     itoa(h,a);
                     lcd_puts(a);
                    }
                  else
                   {
                   lcd_gotoxy(0,0);
                   itoa(h,a);
                   lcd_puts(a);
                   }                 
                  }    
         for(m=0;m<=59;m++)
             {  
              if(m<=9)     
               { 
                lcd_gotoxy(3,0);
                itoa(i,a);
                lcd_puts(a);   
                lcd_gotoxy(4,0);
                itoa(m,a);
                lcd_puts(a);
               }
              else
               {
                lcd_gotoxy(3,0);
                itoa(m,a);
                lcd_puts(a);
               }
            for(s=0;s<=59;s++)
              {
               if(s<=9)     
                { 
                 lcd_gotoxy(6,0);
                 itoa(i,a);
                 lcd_puts(a);
                 lcd_gotoxy(7,0);
                 itoa(s,a);
                 lcd_puts(a);
                 delay_ms(1000);
                }
               else
                {
                 lcd_gotoxy(6,0);
                 itoa(s,a);
                 lcd_puts(a);
                 delay_ms(1000);
                }
            } 
          }        
      }          
   }
}
-----------------------------------------------------------------------------------------------------------------------

Proteus simulation:-