Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3. volatile uint8_t cycleCounter = 0;
  4. volatile uint8_t counter = 0;
  5.  
  6. unsigned char chart_tab[] = {
  7.     0x0F, //0
  8.     0x06, //1
  9.     0x5B, //2
  10.     0x4F, //3
  11.     0x66, //4
  12.     0x6D, //5
  13.     0x7D, //6
  14.     0x07, //7
  15.     0x7F, //8
  16.     0x6F, //9
  17.     0x77, //A
  18.     0x7C, //B
  19.     0x39, //C
  20.     0x5E, //D
  21.     0x79, //E
  22.     0x71, //F
  23. };
  24.  
  25. ISR(TIMER1_COMPA_vect) {
  26.     TCCR1B &= 0b11111000; // Wyłączenie timera
  27.     TCNT1 = 0;
  28.     GIFR |= (1 << INTF0);
  29.     GICR |= (1 << INT0);
  30.  
  31.     if (cycleCounter != 0) {
  32.       cycleCounter--;
  33.       PORTA = ~(_BV(counter % 4));
  34.       TCCR1B |= (1 << CS12);
  35.       return;
  36.     }
  37.     
  38.     asm("nop");
  39.  
  40.     if (PINA >> 4 != 0b00001111) {
  41.         uint8_t mask = 1;
  42.         for (uint8_t row = 0; row < 4; row++) {
  43.             if ((PINA >> 4 & mask) == 0) {
  44.                 PORTD = ~(chart_tab[counter * 4 + (row % 4)]);
  45.             }
  46.             mask = mask << 1;
  47.         }
  48.     }
  49.     counter++;
  50.     if (counter >= 4) {
  51.         counter = 0;
  52.     }
  53.     cycleCounter = 100;
  54.     TCCR1B |= (1 << CS12); // Włączenie timera  
  55. }
  56. void initTimer() {
  57.     TCNT1   = 0;
  58.     TCCR1B |= (1 << WGM12);
  59.     OCR1A   = 1; // Przepełnienie co 20ms
  60.     TIMSK  |= (1 << OCIE1A);
  61.     TCCR1B |= (1 << CS12);
  62.     
  63.     PORTD = 0b10000000;
  64. }
  65. int main() {
  66.     cli();
  67.      DDRD  = 0xFF; // Ustawienie PORTD na wyjście dla diód
  68.      DDRA  = 0x0F; // Pierwsza połowa PORTA to wiersze, a druga to kolumny klawiatury
  69.      PORTA = 0xFF; // Podciągnięcie PORTA
  70.      MCUCR |= (1 << ISC01);
  71.      initTimer();
  72.      sei();
  73.      while(1);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement