Created
January 7, 2014 14:08
-
-
Save niklasf/8299798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#include <util/delay.h> | |
void display_internal(uint8_t mask, uint8_t c) | |
{ | |
uint8_t bm = mask == 0x0F ? 0b00000000 : 0b00001000; | |
uint8_t sh = mask == 0x0F ? 0 : 4; | |
if ((c & mask) >> sh == 0x00) { | |
PORTK = 0b00000011 | bm; | |
PORTF = 0b11111111; | |
} | |
else if ((c & mask) >> sh == 0x01) { | |
PORTK = 0b00000000 | bm; | |
PORTF = 0b00000110; | |
} | |
else if ((c & mask) >> sh == 0x02) { | |
PORTK = 0b00000101 | bm; | |
PORTF = 0b11111011; | |
} | |
else if ((c & mask) >> sh == 0x03) { | |
PORTK = 0b00000100 | bm; | |
PORTF = 0b11111111; | |
} | |
else if ((c & mask) >> sh == 0x04) { | |
PORTK = 0b00000110 | bm; | |
PORTF = 0b11110110; | |
} | |
else if ((c & mask) >> sh == 0x05) { | |
PORTK = 0b00000110 | bm; | |
PORTF = 0b11111101; | |
} | |
else if ((c & mask) >> sh == 0x06) { | |
PORTK = 0b00000111 | bm; | |
PORTF = 0b11111101; | |
} | |
else if ((c & mask) >> sh == 0x07) { | |
PORTK = 0b00000000 | bm; | |
PORTF = 0b00000111; | |
} | |
else if ((c & mask) >> sh == 0x08) { | |
PORTK = 0b00000111 | bm; | |
PORTF = 0b11111111; | |
} | |
else if ((c & mask) >> sh == 0x09) { | |
PORTK = 0b00000110 | bm; | |
PORTF = 0b11111111; | |
} | |
else if ((c & mask) >> sh == 0x0A) { | |
PORTK = 0b00000111 | bm; | |
PORTF = 0b11110111; | |
} | |
else if ((c & mask) >> sh == 0x0B) { | |
PORTK = 0b00000111 | bm; | |
PORTF = 0b11111100; | |
} | |
else if ((c & mask) >> sh == 0x0C) { | |
PORTK = 0b00000011 | bm; | |
PORTF = 0b11111001; | |
} | |
else if ((c & mask) >> sh == 0x0D) { | |
PORTK = 0b00000101 | bm; | |
PORTF = 0b11111110; | |
} | |
else if ((c & mask) >> sh == 0x0E) { | |
PORTK = 0b00000111 | bm; | |
PORTF = 0b11111001; | |
} | |
else if ((c & mask) >> sh == 0x0F) { | |
PORTK = 0b00000111 | bm; | |
PORTF = 0b11110001; | |
} | |
} | |
void display(uint8_t c) { | |
display_internal(0x0F, c); | |
_delay_us(1000); | |
display_internal(0xF0, c); | |
_delay_us(1000); | |
} | |
uint8_t counter = 0; | |
ISR (INT0_vect) { | |
PORTA = ~PINA; | |
counter++; | |
} | |
ISR (INT1_vect) { | |
PORTA = ~PINA; | |
counter--; | |
} | |
int main() | |
{ | |
// led | |
DDRA = 0b11111111; | |
PORTA = 0b00000000; | |
// 7 segment | |
DDRK = 0xFF; | |
DDRF = 0xFF; | |
cli(); | |
EIMSK |= (1 << INT0) | (1 << INT1); | |
EICRA |= (1 << ISC01) | (1 << ISC00) | (1 << ISC11) | (1 << ISC10);; | |
sei(); | |
display(0x00); | |
while (1) { | |
display(counter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment