Code:
#define F_CPU 4000000
//Anzeigen sind verbunden: Anzeige1: PC2, Anzeige2: PC1, Anzeige3: PC3, Anzeige4: PC4
//Segmente sind verbunden: a: PD0, b: PD1, c: PD2, d: PD3, e: PD5, f: PD6, g: PD7, p: PC0
#define n0 0b00111111; //0: a, b, c, e, f
#define n1 0b00000110; //1: c, b
#define n2 0b01011011; //2: a, b, d, e, g
#define n3 0b01001111; //3: a, b, c, d, g
#define n4 0b01100110; //4: b, c, f, g
#define n5 0b01101101; //5: a, c, d, f, g
#define n6 0b01111101; //6: a, c, d, e, f, g
#define n7 0b00000111; //7: a, b, c
#define n8 0b01111111; //8: a, b, c, d, e, f, g
#define n9 0b01101111; //9: a, b, c, d, f, g
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
volatile int output[5];
volatile int error;
int timer;
int run;
int n;
int anzeige[5];
int ziffer[5];
int init;
signed char tast;
int main(void)
{
sei();
GICR |= (1<<INT1); // Externer Interrupt an Pin INT1 Aktivieren
MCUCR |= (1<<ISC11)|(1<<ISC10); // Externer Interrupt auf fallender Flanke
TIMSK |= (1<<TOIE1); // Interrupt aktivieren für Overflow, Timer1 (16bit)
TCCR1B |= (1<<CS10)|(1<<CS11); // 64 Prescaler
TIMSK |= (1<<TOIE2); // Interrupt aktivieren für Overflow, Timer2 (8Bit)
TCCR2 |= (1<<CS22)|(1<<CS21)|(1<<CS20); // 1024 Prescaler
DDRB = 0b11111111;
DDRC = 0b11111111;
DDRD = 0b11110111; // Der 4 Letzte ist INT1, Externer Interrupt
PORTB = 0b00000000;
PORTC = 0b00000000;
if (init == 0) {
ziffer[0]= (1<<PB1);
ziffer[1]= (1<<PB2);
ziffer[2]= (1<<PB3);
ziffer[3]= (1<<PB4);
init = 1;
}
while(1) {
n++;
if (n >=4) {
n = 0;
}
if (error == 1) {
output[0] = 0b00111111;
output[1] = 0b00111111;
output[2] = 0b00111111;
output[3] = 0b00111111;
output[4] = 0b00111111;
}
PORTB = ziffer[n];
PORTC = output[n];
_delay_us(100);
PORTB = 0b00000000;
PORTC = 0b00000000;
}
}
ISR (INT1_vect) {
output [2] = n3;
}
ISR(TIMER1_OVF_vect) {
output [0] = n1;
}
ISR(TIMER2_OVF_vect) {
output [1] = n2;
}
Lesezeichen