#include "main.h"
// https://github.com/lkoepsel/AVR_C
#define LED_ON setBit(PORTB,Bit5)
#define LED_OFF clearBit(PORTB,Bit5)
#define LED_TOGGLE toggleBit(PORTB, Bit5)
#define LED1_ON setBit(PORTB,Bit3)
#define LED1_OFF clearBit(PORTB,Bit3)
#define LED1_TOGGLE toggleBit(PORTB, Bit3)
#define PRESSED checkBit_0(PINB, Bit4)
int main(void)
{
initPortB();
initTimer0();
initInterrupts();
// Hauptschleife
while(1)
{
if (PRESSED)
{
LED_ON;
}
else
{
LED_OFF;
}
}
}
// 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){
LED1_TOGGLE;
counter=0;
}
}