Circuit diagram includes using PORTB5 as output to toggle a LED and PORTC5 for input with button connected to ground.
#include <avr/io.h>
int main(void)
{
DDRB |= (1<<PORTB5);
DDRC &= ~(1<<PORTC5);
PORTC |= (1<<PORTC5);
while (1)
{
if( PINC & (1<<PINC5))
PORTB &= ~(1<<PORTB5);
else
PORTB |= (1<< PORTB5);
}
}
#include <avr/io.h>
int main(void)
{
DDRB |= (1<<PORTB5);
DDRC &= ~(1<<PORTC5);
PORTC |= (1<<PORTC5);
while (1)
{
if( PINC & (1<<PINC5))
PORTB &= ~(1<<PORTB5);
else
PORTB |= (1<< PORTB5);
}
}
No comments:
Post a Comment