initial avr projects (blink + interrupts)
This commit is contained in:
28
LED Blink Input Output/main.c
Normal file
28
LED Blink Input Output/main.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "delay.h"
|
||||
|
||||
int main(void) {
|
||||
// PC2 as output (LED), PC3 as input (button)
|
||||
timer1_init();
|
||||
|
||||
DDRB |= (1<<PB2);
|
||||
DDRB &= ~(1<<PB3);
|
||||
|
||||
// enable internal pull-up on PC3 (important)
|
||||
PORTB |= (1<<PB3);
|
||||
|
||||
timer1_init();
|
||||
|
||||
while(1) {
|
||||
// Button pressed -> pin reads LOW because of pull-up
|
||||
if (PINB & (1<<PB3)) {
|
||||
for (int i=0;i<=20;i++){
|
||||
PORTB |= (1<<PB2); // LED ON
|
||||
delay_ms(200);
|
||||
PORTB &= ~(1<<PB2);
|
||||
delay_ms(200);
|
||||
}
|
||||
} else {
|
||||
PORTB &= ~(1<<PB2); // LED OFF
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user