AVR Programming: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
== ATMega32 IO == | |||
<syntaxhighlight lang="c"> | |||
//ATMega32AVR.c | |||
#include <avr/io.h> | |||
#include <util/delay.h> | |||
int main(void) | |||
{ | |||
//DDRC = 0x01; | |||
DDRC |= (1<<PC0); //data direction resister of PC0 as output | |||
//DDRD = 0x00; | |||
DDRD &= ~(1<<PD0);//data direction resister of PD0 as input | |||
while(1) | |||
{ | |||
if(PIND & (1<<PD0) == 1) //when switch on | |||
{ | |||
PORTC |= (1<<PC0); //LED on | |||
_delay_ms(3000); //3 second delay | |||
PORTC &= ~(1<<PC0); //LED off | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
== References == | == References == | ||
* [https://www.obdev.at/products/crosspack/index.html CrossPack for AVR Development] | * [https://www.obdev.at/products/crosspack/index.html CrossPack for AVR Development] |
Revision as of 05:17, 26 February 2018
ATMega32 IO
//ATMega32AVR.c
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
//DDRC = 0x01;
DDRC |= (1<<PC0); //data direction resister of PC0 as output
//DDRD = 0x00;
DDRD &= ~(1<<PD0);//data direction resister of PD0 as input
while(1)
{
if(PIND & (1<<PD0) == 1) //when switch on
{
PORTC |= (1<<PC0); //LED on
_delay_ms(3000); //3 second delay
PORTC &= ~(1<<PC0); //LED off
}
}
}