Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <util/delay.h>
- #define SEG_PORT PORTB
- #define SEG_DIR DDRB
- #define SEG_A 4
- #define SEG_B 3
- #define SEG_C 1
- #define SEG_D 6
- #define SEG_E 2
- #define SEG_F 5
- #define SEG_G 0
- #define SEG_H 7
- #define DIG_PORT PORTC
- #define DIG_DIR DDRC
- #define DIG_1 0
- #define DIG_2 1
- char tab_seg[] =
- {
- _BV(SEG_A) | _BV(SEG_B) | _BV(SEG_C) | _BV(SEG_D) | _BV(SEG_E) | _BV(SEG_F), // 0
- _BV(SEG_B) | _BV(SEG_C), // 1
- _BV(SEG_A) | _BV(SEG_B) | _BV(SEG_G) | _BV(SEG_D) | _BV(SEG_E), // 2
- _BV(SEG_A) | _BV(SEG_B) | _BV(SEG_C) | _BV(SEG_D) | _BV(SEG_G), // 3
- _BV(SEG_F) | _BV(SEG_G) | _BV(SEG_B) | _BV(SEG_C), // 4
- _BV(SEG_A) | _BV(SEG_F) | _BV(SEG_G) | _BV(SEG_C) | _BV(SEG_D), // 5
- _BV(SEG_F) | _BV(SEG_G) | _BV(SEG_E) | _BV(SEG_A) | _BV(SEG_C) | _BV(SEG_D), // 6
- _BV(SEG_A) | _BV(SEG_B) | _BV(SEG_C), // 7
- _BV(SEG_F) | _BV(SEG_G) | _BV(SEG_E) | _BV(SEG_D) | _BV(SEG_C) | _BV(SEG_B) | _BV(SEG_A), // 8
- _BV(SEG_F) | _BV(SEG_G) | _BV(SEG_B) | _BV(SEG_A) | _BV(SEG_C) | _BV(SEG_D), // 9
- };
- char dot;
- int main(void)
- {
- SEG_PORT = 0xFF;
- SEG_DIR = 0xFF;
- DIG_PORT = 0x00;
- DIG_DIR = (1 << DIG_1) | (1 << DIG_2);
- dot = 0;
- while(1)
- {
- DIG_PORT = _BV(DIG_1);
- for (int i = 0; i < 10; ++i)
- {
- SEG_PORT = tab_seg[i];
- SEG_PORT |= _BV(SEG_H);
- _delay_ms(1000);
- }
- DIG_PORT = _BV(DIG_2);
- for (int i = 0; i < 10; ++i)
- {
- SEG_PORT = tab_seg[i];
- _delay_ms(1000);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement