Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <avr/interrupt.h>
- volatile uint8_t cycleCounter = 0;
- volatile uint8_t counter = 0;
- unsigned char chart_tab[] = {
- 0x0F, //0
- 0x06, //1
- 0x5B, //2
- 0x4F, //3
- 0x66, //4
- 0x6D, //5
- 0x7D, //6
- 0x07, //7
- 0x7F, //8
- 0x6F, //9
- 0x77, //A
- 0x7C, //B
- 0x39, //C
- 0x5E, //D
- 0x79, //E
- 0x71, //F
- };
- ISR(TIMER1_COMPA_vect) {
- TCCR1B &= 0b11111000; // Wyłączenie timera
- TCNT1 = 0;
- GIFR |= (1 << INTF0);
- GICR |= (1 << INT0);
- if (cycleCounter != 0) {
- cycleCounter--;
- PORTA = ~(_BV(counter % 4));
- TCCR1B |= (1 << CS12);
- return;
- }
- asm("nop");
- if (PINA >> 4 != 0b00001111) {
- uint8_t mask = 1;
- for (uint8_t row = 0; row < 4; row++) {
- if ((PINA >> 4 & mask) == 0) {
- PORTD = ~(chart_tab[counter * 4 + (row % 4)]);
- }
- mask = mask << 1;
- }
- }
- counter++;
- if (counter >= 4) {
- counter = 0;
- }
- cycleCounter = 100;
- TCCR1B |= (1 << CS12); // Włączenie timera
- }
- void initTimer() {
- TCNT1 = 0;
- TCCR1B |= (1 << WGM12);
- OCR1A = 1; // Przepełnienie co 20ms
- TIMSK |= (1 << OCIE1A);
- TCCR1B |= (1 << CS12);
- PORTD = 0b10000000;
- }
- int main() {
- cli();
- DDRD = 0xFF; // Ustawienie PORTD na wyjście dla diód
- DDRA = 0x0F; // Pierwsza połowa PORTA to wiersze, a druga to kolumny klawiatury
- PORTA = 0xFF; // Podciągnięcie PORTA
- MCUCR |= (1 << ISC01);
- initTimer();
- sei();
- while(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement