Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <avr/interrupt.h>
- typedef enum {A,B,C,D, screen} states_t;
- states_t stato = A;
- volatile uint8_t portbhistory = 0xFF;
- uint16_t c=0;
- uint16_t b=0;
- uint16_t d=0;
- uint16_t i=0;
- int main (void) {
- DDRD &= ~((1 << DDD4) | (1 << DDD5) | (1 << DDD6)|(1 << DDD2)|(1 << DDD3));
- DDRD &= ~(1 << DDD2);
- DDRD &= ~(1 << DDD3);
- PORTD=0xff;
- DDRC=0xff;
- PCICR |= (1 << PCIE2);
- PCMSK2 |= (1 << PCINT18) | (1 << PCINT19) | (1 << PCINT20)| (1 << PCINT21)| (1 << PCINT22);
- TCCR1B |= (1 << WGM12); // Set the Timer Mode to CTC (Mode 4)
- // Set the value that you want to count to // [ (clock_speed / Prescaler_value) * Desired_interval_in_Seconds ] - 1 // [ (16000000 / 1024) * 0.2 ] -1 = 3124
- OCR1A = 3124;
- // Set interrupt on compare match
- TCCR1B |= (1 << CS12) | (1 << CS10); // starts the timer, set prescaler to 1024
- TIMSK1 |= (1 << OCIE1A);
- sei();
- while (1) {
- switch (stato) {
- case A :
- c=0;
- if(i==5){ PORTC=1;}
- if(i==10){ PORTC=3;}
- while(i>=5 & i<10){if(c==1){stato=B;
- PORTC=0;}
- if(i==15){ PORTC=7;}
- if(i==20){ PORTC=0xf;}
- if(i==25){PORTC=0;}
- break;
- case B: c=0;
- if(i==5){ PORTC=1;}
- if(i==10){ PORTC=3;}
- while(i>=15 & i<20){if(c==1){stato=C; PORTC=0;}
- if(i==15){ PORTC=7;}
- if(i==20){ PORTC=0xf;}
- if(i==25){PORTC=0;}
- break;
- case C : b=0; if(i==5){ PORTC=1;}
- if(i==10){ PORTC=3;}
- while(i>=10 & i<15){if(b==1){stato=D; PORTC=0;}
- if(i==15){ PORTC=7;}
- if(i==20){ PORTC=0xf;}
- if(i==25){PORTC=0;}
- break;
- case D : d=0; if(i==5){ PORTC=1;}
- if(i==10){ PORTC=3;}
- while(i>=20 & i<25){if(d==1){stato=screen; PORTC=0;}
- if(i==15){ PORTC=7;}
- if(i==20){ PORTC=0xf;}
- if(i==25){PORTC=0;}
- break;
- case screen : if(i==5){ PORTC=0xf;}
- if(i==10){ PORTC=0; i=0;}
- break;
- }
- }
- }
- ISR (TIMER1_COMPA_vect){i++;
- if(i==26){i=0;}}
- ISR (PCINT2_vect) { uint8_t changedbits;
- changedbits = PIND ^ portbhistory; portbhistory = PIND;
- if(changedbits & (1 << PIND2)) { /* PCINT0 changed */ if( (PIND & (1 << PIND2)) == 1 ) { /* LOW to HIGH pin change */ } else { d=1;} }
- if(changedbits & (1 << PIND3)) { /* PCINT0 changed */ if( (PIND & (1 << PIND3)) == 1 ) { /* LOW to HIGH pin change */ } else {c=1; } }
- if(changedbits & (1 << PIND5)) { /* PCINT0 changed */ if( (PIND & (1 << PIND5)) == 1 ) { /* LOW to HIGH pin change */ } else { b=1;} }
- if(changedbits & (1 << PIND4)) { /* PCINT0 changed */ if( (PIND & (1 << PIND4)) == 1 ) { /* LOW to HIGH pin change */ } else { /* HIGH to LOW pin change */ } }
- if(changedbits & (1 << PIND6)) { /* PCINT0 changed */ if( (PIND & (1 << PIND6)) == 1 ) { /* LOW to HIGH pin change */ } else { /* HIGH to LOW pin change */ } }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement