Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <util/delay.h>
- #include <avr/interrupt.h>
- #define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT))
- #define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))
- #define FLIPBIT(ADDRESS,BIT) (ADDRESS ^= (1<<BIT))
- #define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT))
- volatile int counter;
- void set_digit(int digit) {
- if (digit == 0) {
- PORTB = 0b00001110;
- PORTD = 0b11100000;
- } else if (digit == 1) {
- PORTD = 0b10000000;
- PORTB = 0b00001000;
- } else if (digit == 2) {
- PORTB = 0b00001101;
- PORTD = 0b01100000;
- } else if (digit == 3) {
- PORTB = 0b00001101;
- PORTD = 0b11000000;
- } else if (digit == 4) {
- PORTB = 0b00001011;
- PORTD = 0b10000000;
- } else if (digit == 5) {
- PORTB = 0b00000111;
- PORTD = 0b11000000;
- } else if (digit == 6) {
- PORTB = 0b00000111;
- PORTD = 0b11100000;
- } else if (digit == 7) {
- PORTB = 0b00001100;
- PORTD = 0b10000000;
- } else if (digit == 8) {
- PORTB = 0b00001111;
- PORTD = 0b11100000;
- } else if (digit == 9) {
- PORTB = 0b00001111;
- PORTD = 0b11000000;
- }
- }
- ISR(INT0_vect) {
- counter = (counter + 1) % 10;
- set_digit(counter);
- }
- int main()
- {
- int i;
- DDRD = PORTD = DDRB = PORTB = 0;
- for (i = 5; i < 8; i++) {
- DDRD |= (1 << i);
- }
- for (i = 0; i < 4; i++) {
- DDRB |= (1 << i);
- }
- PORTD |= 1 << 2;
- counter = 0;
- CLEARBIT(EICRA, ISC01);
- SETBIT(EICRA, ISC00);
- sei(); // allow interrupts
- SETBIT(EIMSK, 0);
- set_digit(counter);
- while(1) { }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement