P5 initial
This commit is contained in:
34
Abgaben/P4/keys.c
Normal file
34
Abgaben/P4/keys.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "keys.h"
|
||||
|
||||
void setupTimer0() {
|
||||
// Configure Timer0 for CTC mode
|
||||
TCCR0A |= (1 << WGM01); // Set Waveform Generation Mode bits for CTC
|
||||
TCCR0B |= (1 << CS01) | (1 << CS00); // Set prescaler to 64
|
||||
OCR0A = 249; // Set Output Compare Register to 249 for ~1ms interrupt
|
||||
TIMSK0 |= (1 << OCIE0A); // Enable Timer0 Output Compare A Match interrupt
|
||||
}
|
||||
|
||||
void setupRegisters(){
|
||||
DDRD = 0xff; // Data direction register D (D0 -> D6) as output
|
||||
// PORTD = 0xff; // setting bit for 7-segment show 0
|
||||
// => spielt keine Rolle, wird von der while Schleife <20>bernommen
|
||||
|
||||
DDRB = 0x01; // Data direction register B (B0) as output and DDRB (B1, B2) as input
|
||||
PORTB |= (1 << PINB1) | (1 << PINB2) ; // setting bit for teens B0=0 and SW1-2
|
||||
// PINB=0 => start with LED3 (Einer)
|
||||
|
||||
// mit unserem Atmega nicht m<>glich, da keine PCINT8_vect und PCINT9_vect vorhanden
|
||||
// DDRC = 0x00; // Data direction register C as input for SW1 and SW2
|
||||
// PORTC |= (1<<PINC0) | (1<<PINC1); // settings pins for SW1 -> PINC0 and SW2 -> PINC1
|
||||
|
||||
cli(); // clear global interrupt flag: interrupts will be immediately disabled
|
||||
PCICR |= 0x01; // Pin Change Interrupt Control Register: turn on PortB
|
||||
PCMSK0 |= (1 << PINB1) | (1 << PINB2); // trigger interrupt when SW1 or SW2 is pressed
|
||||
sei(); // set global interrupt enable
|
||||
|
||||
}
|
||||
|
||||
void init(){
|
||||
setupTimer0();
|
||||
setupRegisters();
|
||||
}
|
||||
Reference in New Issue
Block a user