initial avr projects (blink + interrupts)
This commit is contained in:
35
interrupts/main.c
Normal file
35
interrupts/main.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "delay.h"
|
||||
#include <avr/interrupt.h>
|
||||
volatile uint8_t flag=0;
|
||||
|
||||
int main(void){
|
||||
timer1_init();
|
||||
DDRC |= (1<<PC0); // PB1 (D9)
|
||||
// prescaler 8
|
||||
DDRD &= ~(1 << PD2);
|
||||
PORTD |= (1 << PD2);
|
||||
EICRA &= ~(1<<ISC00);
|
||||
EICRA |= (1<<ISC01);
|
||||
EIMSK |= (1<<INT0);
|
||||
|
||||
sei();
|
||||
while(1){
|
||||
if(flag){
|
||||
|
||||
flag=0;
|
||||
PORTC |=(1<<PC0);
|
||||
delay_ms(500);
|
||||
PORTC &=~(1<<PC0);
|
||||
delay_ms(500);
|
||||
}
|
||||
else{
|
||||
PORTC |=(1<<PC0);
|
||||
delay_ms(50);
|
||||
PORTC &=~(1<<PC0);
|
||||
delay_ms(50);
|
||||
} // 75%
|
||||
}
|
||||
}
|
||||
ISR(INT0_vect){
|
||||
flag=1;
|
||||
}
|
||||
Reference in New Issue
Block a user