#include "main.h"
// https://github.com/lkoepsel/AVR_C
#define LED_GREEN_ON setBit(PORTB,Bit5)
#define LED_GREEN_OFF clearBit(PORTB,Bit5)
#define LED_GREEN_TOGGLE toggleBit(PORTB, Bit5)
#define LED_RED_ON setBit(PORTB,Bit3)
#define LED_RED_OFF clearBit(PORTB,Bit3)
#define LED_RED_TOGGLE toggleBit(PORTB, Bit3)
#define LED_BLUE_ON setBit(PORTB,Bit2)
#define LED_BLUE_OFF clearBit(PORTB,Bit2)
#define LED_BLUE_TOGGLE toggleBit(PORTB, Bit2)
#define LED_YELLOW_ON setBit(PORTB,Bit1)
#define LED_YELLOW_OFF clearBit(PORTB,Bit1)
#define LED_YELLOW_TOGGLE toggleBit(PORTB, Bit1)
#define PRESSED checkBit_0(PINB, Bit4)
int main(void)
{
initPortB();
initTimer0();
initTimer1();
initTimer2();
initInterrupts();
// Hauptschleife
while(1)
{
if (PRESSED)
{
LED_YELLOW_OFF;
}
else
{
LED_YELLOW_ON;
}
}
}
// Timer0 Interrupt Service Routine
ISR(TIMER0_OVF_vect){
// entered every 64µs*256@16Mhz => 16.384ms@16Mhz
static int counter = 0;
#define POSTSCALER 31 // 31*16.384ms = 507.904ms
counter++;
if (counter >= POSTSCALER){
LED_GREEN_TOGGLE;
counter=0;
}
}
// Timer1 Interrupt Service Routine
ISR (TIMER1_COMPA_vect){
// enter on compare match A
LED_BLUE_TOGGLE;
}
// Timer2 Interrupt Service Routine
ISR (TIMER2_COMPA_vect){
// enter on compare match A
// LED_TOGGLE;
static int counter = 0;
#define POSTSCALER 31 // 31*16.384ms = 507.904ms
counter++;
if (counter >= POSTSCALER){
LED_RED_TOGGLE;
counter=0;
}
}