ATMEGA 8535 LED PROGRAM USING EXTERNAL SWITCH

In the previous post mentioned about switch (Developer board configuration),that board have four switch and four led
1.sw1

2.sw2

3.sw3

4.sw4

After executing program “led1 will glow while pressing s1” similarly will take place for others also.

PROGRAM:

#include<avr/io.h>        //This is the header for AVR Microcontroller.

int main(void)
 {    
    PORTC=0X00;            //PortC initiallization as all bits low.
    DDRC=0XF8;            //PortC data direction declaration as output.
    
    PORTA=0XFF;            //PortA initiallization as all bits high (Pull-up Mode).
    DDRA=0X00;            //PortA data direction declaration as input.
    
    while(1)            //This is for the the infinity loop.
    {    
        if((PINA & 0x10)==0x00)            //checking for switch press at s1.
        {            
            PORTC=0x10;                        //LED1 ON
        }
        
        if((PINA & 0x20)==0x00)            //checking for switch press at s2.
        {
            PORTC=0x20;                     //LED2 ON
        }
        
        if((PINA & 0x40)==0x00)            //checking for switch press at s3.
        {
            PORTC=0x40;                     //LED3 ON
        }
        
        if((PINA & 0x80)==0x00)            //checking for switch press at s4.
        {
            PORTC=0x08;                     //BZ ON
            while((PINA & 0x80)==0x00);    //continuosly checking for s4
            PORTC=0x00;                     //BZ OFF
        }
        
        //else
        //PORTC=0X00;
    }
}
BY

SARANKUMAR

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s