Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.50 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3.  
  4. #define SEG_PORT PORTB
  5. #define SEG_DIR DDRB
  6. #define SEG_A 4
  7. #define SEG_B 3
  8. #define SEG_C 1
  9. #define SEG_D 6
  10. #define SEG_E 2
  11. #define SEG_F 5
  12. #define SEG_G 0
  13. #define SEG_H 7
  14.  
  15. #define DIG_PORT PORTC
  16. #define DIG_DIR DDRC
  17. #define DIG_1 0
  18. #define DIG_2 1
  19.  
  20. char tab_seg[] =
  21. {
  22.     _BV(SEG_A) | _BV(SEG_B) | _BV(SEG_C) | _BV(SEG_D) | _BV(SEG_E) | _BV(SEG_F),    // 0
  23.     _BV(SEG_B) | _BV(SEG_C),                                                        // 1
  24.     _BV(SEG_A) | _BV(SEG_B) | _BV(SEG_G) | _BV(SEG_D) | _BV(SEG_E),                 // 2
  25.     _BV(SEG_A) | _BV(SEG_B) | _BV(SEG_C) | _BV(SEG_D) | _BV(SEG_G),                 // 3
  26.     _BV(SEG_F) | _BV(SEG_G) | _BV(SEG_B) | _BV(SEG_C),                              // 4
  27.     _BV(SEG_A) | _BV(SEG_F) | _BV(SEG_G) | _BV(SEG_C) | _BV(SEG_D),                             // 5
  28.     _BV(SEG_F) | _BV(SEG_G) | _BV(SEG_E) | _BV(SEG_A) | _BV(SEG_C) | _BV(SEG_D),                                // 6
  29.     _BV(SEG_A) | _BV(SEG_B) | _BV(SEG_C),                               // 7
  30.     _BV(SEG_F) | _BV(SEG_G) | _BV(SEG_E) | _BV(SEG_D) | _BV(SEG_C) | _BV(SEG_B) | _BV(SEG_A),                               // 8
  31.     _BV(SEG_F) | _BV(SEG_G) | _BV(SEG_B) | _BV(SEG_A) | _BV(SEG_C) | _BV(SEG_D),                                // 9
  32.  
  33.  
  34. };
  35.  
  36. char dot;
  37.  
  38. int main(void)
  39. {
  40.     SEG_PORT = 0xFF;
  41.     SEG_DIR = 0xFF;
  42.  
  43.     DIG_PORT = 0x00;
  44.     DIG_DIR = (1 << DIG_1) | (1 << DIG_2);
  45.  
  46.     dot = 0;
  47.  
  48.     while(1)
  49.     {
  50.         DIG_PORT = _BV(DIG_1);
  51.  
  52.         for (int i = 0; i < 10; ++i)
  53.         {
  54.             SEG_PORT = tab_seg[i];
  55.             SEG_PORT |= _BV(SEG_H);
  56.             _delay_ms(1000);
  57.         }
  58.  
  59.         DIG_PORT = _BV(DIG_2);
  60.         for (int i = 0; i < 10; ++i)
  61.         {
  62.             SEG_PORT = tab_seg[i];
  63.             _delay_ms(1000);
  64.         }
  65.  
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement