Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Cezary Zaprawa
- #include <avr/io.h>
- #include <avr/interrupt.h>
- volatile uint8_t columnPosition = 0;
- volatile uint8_t rowPosition = 0;
- ISR(TIMER1_OVF_vect) {
- DDRA = (1 << columnPosition);
- PORTA = ~(1 << columnPosition);
- if((PINA & 0xf0) != 0xf0) {
- rowPosition = PINA;
- if(!(rowPosition & (1 << 4))) rowPosition = 0;
- else if(!(rowPosition & (1 << 5))) rowPosition = 1;
- else if(!(rowPosition & (1 << 6))) rowPosition = 2;
- else if(!(rowPosition & (1 << 7))) rowPosition = 3;
- PORTD = rowPosition*4 + columnPosition;
- }
- columnPosition++;
- if(columnPosition == 4) columnPosition = 0;
- }
- void init() {
- cli();
- ICR1 = 15625;
- TCCR1A |= (1 << WGM11);
- TCCR1B |= (1 << WGM12) | (1 << WGM13) | (1 << CS11) | (1 << CS10);
- TIMSK |= (1 << TOIE1);
- DDRD = 0xFF;
- DDRA = 0x0F;
- PORTA = 0xFF;
- PORTD = 0xFF;
- sei();
- }
- int main(void) {
- init();
- while(1) {
- asm("nop");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement