AVR Programming

From Chorke Wiki
Revision as of 05:29, 26 February 2018 by Shahed (talk | contribs) (→‎References)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

ATMega32 IO

//ATMega32AVR.c

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

int main(void)
{
    //DDRC = 0x01;
    DDRC |= (1<<PC0); //PC0 as output
    
    //DDRD = 0x00;
    DDRD &= ~(1<<PD0);//PD0 as input
    while(1)
    {
        if(PIND & (1<<PD0) == 1) //when switch on
        {
            PORTC |= (1<<PC0);   //LED on
            _delay_ms( 3000 );   //delay 3 second
            PORTC &= ~(1<<PC0);  //LED off
        }
    }
    return 0;
}

References