/* * Empfaenger_6x7Segment.cpp * * Created: 18.02.2016 19:11:46 * Author: Error404 */ #define F_CPU 2000000UL #define dvcc DDRF #define vcc PORTF #define ddata DDRD #define data PORTD #define f 60 //Anzeige-Frequenz in [Hz] #include #include #include unsigned char i=0,aktion=0,eingang=0,speicher[6]={0,1,2,3,4,5},pc1=1,eingangtast=0,zeit=0; bool test=0; void ausgabe(unsigned char); void tim1_init(void); void tim3_init(void); void pc0_init(void); void ext0_init(void); ISR(TIMER1_COMPA_vect) //Alle 1/(f*6) Sekunden //Ausgabe auf 6x7Segment { vcc&=~0b11110011; ausgabe(speicher[i]); if(i<=1) vcc|=(1<=6) i=0; if(zeit<36)zeit++; } ISR(TIMER3_COMPA_vect) //Manchester Dekodierung { if(aktion==2) aktion++; else if(aktion>=3&&aktion<=6) { if(PINB&(1<<0)) //1 { eingang|=(1<<(aktion-3)); } else if(!(PINB&(1<<0))) //0 { eingang&=~(1<<(aktion-3)); } aktion++; } else if(aktion>=7) { if(eingang==12) { for(int j=5;j>0;j--) speicher[j]=speicher[j-1]; speicher[0]=1; for(int j=5;j>0;j--) speicher[j]=speicher[j-1]; speicher[0]=2; } else if(eingang==11) { for(int j=5;j>0;j--) speicher[j]=speicher[j-1]; speicher[0]=1; for(int j=5;j>0;j--) speicher[j]=speicher[j-1]; speicher[0]=1; } else { for(int j=5;j>0;j--) speicher[j]=speicher[j-1]; speicher[0]=eingang; } eingang=0; OCR3A=65535; aktion=0; } } ISR(PCINT0_vect) //PB0 //Timer 3 Zeitanpassung { if(aktion==1) {OCR3A=TCNT3; TCNT3=3*OCR3A/4; aktion++;} if(aktion==0) {TCNT3=0; aktion++;} } ISR(INT0_vect) //PD0 //USB-Tastatur Clock { if(pc1==1||pc1==10) pc1++; else if(pc1>=2&&pc1<=9) { if(PINB&(1<<1)) //USB-Tastatur Daten=1 { eingangtast|=(1<<(pc1-2)); } else if(!(PINB&(1<<1))) //USB-Tastatur Daten=0 { eingangtast&=~(1<<(pc1-2)); } pc1++; if(pc1==10) { for(int j=5;j>0;j--) speicher[j]=speicher[j-1]; //auf 7 Segment-Anzeigen nach links verschieben if(eingangtast==0x16) speicher[0]=1; //Kodierungen if(eingangtast==0x1E) speicher[0]=2; if(eingangtast==0x26) speicher[0]=3; if(eingangtast==0x25) speicher[0]=4; if(eingangtast==0x2E) speicher[0]=5; if(eingangtast==0x36) speicher[0]=6; if(eingangtast==0x3D) speicher[0]=7; if(eingangtast==0x3E) speicher[0]=8; if(eingangtast==0x46) speicher[0]=9; } } else if(pc1>=10) pc1=1; } int main(void) { dvcc=255; //output ddata=254; //output bis auf PD0 vcc=255; //alle vcc=1 data=254; //alle daten=1 außer PD0...also nichts angezeigt DDRB&=~(1<<0); DDRB&=~(1<<1); PORTB&=~(1<<0); PORTB&=~(1<<1); tim1_init(); tim3_init(); pc0_init(); ext0_init(); sei(); while(1) { } } void ausgabe(unsigned char zahl) { if(zahl==0) data=0b10000000; //0b11000000 if(zahl==1) data=0b11110010; //0b11111001 if(zahl==2) data=0b01001000; //0b10100100 if(zahl==3) data=0b01100000; //0b10110000 if(zahl==4) data=0b00110010; //0b10011001 if(zahl==5) data=0b00100100; //0b10010010 if(zahl==6) data=0b00000100; //0b10000010 if(zahl==7) data=0b11110000; //0b11111000 if(zahl==8) data=0b00000000; //0b10000000 if(zahl==9) data=0b00100000; //0b10010000 } void tim1_init() { TCNT1=0; OCR1A=F_CPU/(6*f); TCCR1B|=(1<