SHARE
TWEET

Untitled

a guest Apr 22nd, 2017 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3. #include <util/atomic.h>
  4. #include <util/delay.h>
  5. #include <stdint.h>
  6.  
  7.  
  8.  
  9. #define LIGHT_DAY       _BV(PC0)
  10. #define LIGHT_BRAKE     _BV(PC1)
  11. #define LIGHT_DIR_R     _BV(PC2)
  12. #define LIGHT_REV       _BV(PC3)
  13. #define LIGHT_DIR_L     _BV(PC4)
  14. #define LIGHT_STROBO_L  _BV(PC5)
  15. #define LIGHT_STROBO_R  _BV(PC6)
  16. #define LIGHT_NIGHT     _BV(PC7)
  17.  
  18.  
  19.  
  20. #define SET_LIGHTS(LIGHTS)  PORTC |= (LIGHTS);
  21. #define CLR_LIGHTS(LIGHTS)  PORTC &= ~(LIGHTS);
  22.  
  23.  
  24.  
  25. typedef uint8_t Time;
  26.  
  27.  
  28.  
  29. volatile Time systemTime = 0;
  30.  
  31.  
  32.  
  33. ISR(TIMER1_COMPA_vect){
  34.     systemTime++;
  35. }
  36.  
  37.  
  38.  
  39. void initAll(){
  40.     DDRC = 0xFF;
  41.  
  42.     // system clock
  43.     TCCR1B = _BV(WGM12) | _BV(CS12);
  44.     TCNT1  = 0;
  45.     OCR1A  = 31250;
  46.     TIMSK  = _BV(OCIE1A);
  47.  
  48.     sei();
  49. }
  50.  
  51.  
  52.  
  53. int main(){
  54.     initAll();
  55.  
  56.     while(1){
  57.         PORTC = systemTime;
  58.     }
  59.  
  60.     return 0;
  61. }
RAW Paste Data
Top