95 lines
1.9 KiB
C
Executable file
95 lines
1.9 KiB
C
Executable file
#include <avr/io.h>
|
|
#include <avr/sleep.h>
|
|
#include <avr/interrupt.h>
|
|
|
|
uint8_t volatile pina;
|
|
uint8_t volatile pinb;
|
|
|
|
ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect));
|
|
ISR(PCINT0_vect){
|
|
uint8_t difa = (pina ^ PINA) & PINA;
|
|
uint8_t difb = (pinb ^ PINB) & PINB;
|
|
|
|
if(difa == 1) {
|
|
// S1 gedrückt: blau heller
|
|
if (OCR0A >= 25) {
|
|
OCR0A = OCR0A - 25;
|
|
}
|
|
} else if (difa == 2) {
|
|
//S2 gedrückt: blau schwaecher
|
|
if (OCR0A <= 230) {
|
|
OCR0A = OCR0A + 25;
|
|
}
|
|
} else if (difa == 4) {
|
|
//S3 gedrückt: grün heller
|
|
if (OCR0B >= 25) {
|
|
OCR0B = OCR0B - 25;
|
|
}
|
|
} else if (difa == 8) {
|
|
//S4 gedrückt: grüner schwaecher
|
|
if (OCR0B <= 230) {
|
|
OCR0B = OCR0B + 25;
|
|
}
|
|
} else if (difb == 2) {
|
|
//S5 gedrückt: rot heller
|
|
if (OCR1A >= 25) {
|
|
OCR1A = OCR1A - 25;
|
|
}
|
|
}
|
|
else if (difb == 1) {
|
|
//S6 gedrückt: rot schwaecher
|
|
if (OCR1A <= 230) {
|
|
OCR1A = OCR1A + 25;
|
|
}
|
|
}
|
|
|
|
pina = PINA;
|
|
pinb = PINB;
|
|
}
|
|
|
|
|
|
|
|
// Set fuses for 8MHz internal clock with slow rising power
|
|
FUSES =
|
|
{
|
|
.low = (FUSE_SUT0 & FUSE_CKSEL3 & FUSE_CKSEL2 & FUSE_CKSEL0),
|
|
.high = FUSE_SPIEN,
|
|
.extended = EFUSE_DEFAULT
|
|
};
|
|
|
|
|
|
|
|
int main()
|
|
{
|
|
OCR0A = 255;
|
|
OCR0B = 255;
|
|
OCR1A = 255;
|
|
|
|
TCCR0B = (1 << CS01) | (1 << CS00);
|
|
TCCR0A = (1 << WGM01) | (1 << WGM00) | (1 << COM0A1) | (1 << COM0A0) | (1 << COM0B1) | (1 << COM0B0);
|
|
|
|
// 16 bit zähler
|
|
TCCR1B = (1 << CS11) | (1 << CS10) | (1 << WGM12);
|
|
TCCR1A = (1 << WGM10) | (1 << COM1A1) | (1 << COM1A0);
|
|
|
|
|
|
|
|
// Set A7, A6 and B2 as output
|
|
DDRA = (1 << DDA7) | (1 << DDA6);
|
|
DDRB = (1 << DDB2);
|
|
|
|
pina = PINA;
|
|
pinb = PINB;
|
|
|
|
// Enable Pin Change Interrupts for switches
|
|
GIMSK = (1 << PCIE1) |(1 << PCIE0);
|
|
PCMSK0 = (1 << PCINT0) | (1 << PCINT1) | (1 << PCINT2) | (1 << PCINT3);
|
|
PCMSK1 = (1 << PCINT8) | (1 << PCINT9);
|
|
|
|
sei();
|
|
|
|
while (1) {
|
|
// sleep_enable();
|
|
}
|
|
return 0;
|
|
}
|