Guest User

egaistek

a guest
Aug 14th, 2009
239
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define F_CPU 1000000UL // 1 MHz
  2.  
  3. #include <avr/io.h>
  4. #include <util/delay.h>
  5.  
  6. // segment A1 connected to port D, bit 2 (PD2)
  7. #define SEG_A1_ON PORTD &= ~(1 << 2)
  8. #define SEG_A1_OFF PORTD |= (1 << 2)
  9.  
  10. #define SEG_A2_ON PORTD &= ~(1 << 3)
  11. #define SEG_A2_OFF PORTD |= (1 << 3)
  12.  
  13. #define SEG_B_ON PORTD &= ~(1 << 4)
  14. #define SEG_B_OFF PORTD |= (1 << 4)
  15.  
  16. #define SEG_C_ON PORTD &= ~(1 << 5)
  17. #define SEG_C_OFF PORTD |= (1 << 5)
  18.  
  19. #define SEG_D1_ON PORTD &= ~(1 << 7)
  20. #define SEG_D1_OFF PORTD |= (1 << 7)
  21.  
  22. #define SEG_D2_ON PORTD &= ~(1 << 6)
  23. #define SEG_D2_OFF PORTD |= (1 << 6)
  24.  
  25. #define SEG_E_ON PORTB &= ~(1 << 0)
  26. #define SEG_E_OFF PORTB |= (1 << 0)
  27.  
  28. #define SEG_F_ON PORTB &= ~(1 << 1)
  29. #define SEG_F_OFF PORTB |= (1 << 1)
  30.  
  31. #define SEG_G1_ON PORTB &= ~(1 << 2)
  32. #define SEG_G1_OFF PORTB |= (1 << 2)
  33.  
  34. #define SEG_G2_ON PORTB &= ~(1 << 3)
  35. #define SEG_G2_OFF PORTB |= (1 << 3)
  36.  
  37. #define SEG_H_ON PORTB &= ~(1 << 4)
  38. #define SEG_H_OFF PORTB |= (1 << 4)
  39.  
  40. #define SEG_J_ON PORTD &= ~(1 << 5)
  41. #define SEG_J_OFF PORTD |= (1 << 5)
  42.  
  43. #define SEG_K_ON PORTC &= ~(1 << 0)
  44. #define SEG_K_OFF PORTC |= (1 << 0)
  45.  
  46. #define SEG_L_ON PORTC &= ~(1 << 1)
  47. #define SEG_L_OFF PORTC |= (1 << 1)
  48.  
  49. #define SEG_M_ON PORTC &= ~(1 << 2)
  50. #define SEG_M_OFF PORTC |= (1 << 2)
  51.  
  52. #define SEG_N_ON PORTC &= ~(1 << 3)
  53. #define SEG_N_OFF PORTC |= (1 << 3)
  54.  
  55. #define SEG_DP_ON PORTC &= ~(1 << 4)
  56. #define SEG_DP_OFF PORTC |= (1 << 4)
  57.  
  58. void delay_ms(int count)
  59. {
  60.     _delay_ms(count);
  61. }
  62.  
  63. void ioinit()
  64. {
  65.     DDRB = 0b11111111;
  66.     DDRC = 0b11111111;
  67.     DDRD = 0b11111110;
  68.    
  69.     PORTB = 0xff;
  70.     PORTC = 0xff;
  71.     PORTD = 0xff;
  72. }
  73.  
  74. int main()
  75. {
  76.     ioinit();
  77.    
  78.     while(1) {
  79.    
  80.         #define BLINK 500
  81.        
  82.     SEG_A1_ON; delay_ms(BLINK);
  83.     SEG_A1_OFF;
  84.    
  85.     SEG_A2_ON; delay_ms(BLINK);
  86.     SEG_A2_OFF;
  87.    
  88.     SEG_B_ON; delay_ms(BLINK);
  89.     SEG_B_OFF;
  90.    
  91.     SEG_C_ON; delay_ms(BLINK);
  92.     SEG_C_OFF;
  93.    
  94.     SEG_D2_ON; delay_ms(BLINK);
  95.     SEG_D2_OFF;
  96.    
  97.     SEG_D1_ON; delay_ms(BLINK);
  98.     SEG_D1_OFF;
  99.    
  100.     SEG_E_ON; delay_ms(BLINK);
  101.     SEG_E_OFF;
  102.    
  103.     SEG_F_ON; delay_ms(BLINK);
  104.     SEG_F_OFF;
  105.    
  106.     }
  107. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×