rendered paste body#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
#include <avr/sfr_defs.h>
#include <util/delay.h>
#define F_CPU 4000000
#define STOP 0
#define RUN 1
uint8_t state;
volatile uint8_t ledCount = 0;
void enableAllStops(){
PORTD |=(1<<PD6)|(1<<PD4);
}
void disableAllStops(){
PORTD &=~(1<<PD6)&~(1<<PD4);
}
void enableRun(){
}
void disableRun(){
PORTD &=~(1<<PD5);
}
SIGNAL(SIG_INTERRUPT0){
ledCount=1;
//RESET
if(bit_is_set(PINA,PA0) && state==STOP){
disableAllStops();
PORTD |=(1<<PD5);
state=RUN;
}
//SW1
if(bit_is_set(PINA,PA1) && state==RUN){
disableRun();
PORTD |=(1<<PD6);
state=STOP;
}
//SW2
if(bit_is_set(PINA,PA2) && state==RUN){
disableRun();
PORTD |=(1<<PD4);
state=STOP;
}
}
int main(void){
state=STOP;
GICR=0xC0;
MCUCR=0x01;
sei();
DDRD |= (1<<PD6)|(1<<PD5)|(1<<PD4);
DDRB |= (1<<PB0);
DDRA = 0x00; //alla pinnar i porta som input riktning
PORTD |= (1 << PD2);
PORTA = 0x00; //pullup 0 pa alla pinnar
PORTB |=(1<<PB0);
enableAllStops();
while (1) {
if(ledCount==1){
PORTB &=~(1<<PB0);
_delay_ms(400);
ledCount=0;
}
else{
PORTB |=(1<<PB0);
}
return 0;
}
}