uwezi

20211116_1TE663_lab4_01.c

Nov 16th, 2021 (edited)
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.50 KB | None | 0 0
  1. #define F_CPU 1000000UL
  2.  
  3. #include <avr/io.h>
  4. #include <util/delay.h>
  5. #include <avr/interrupt.h>
  6.  
  7. // font for a 7-segment display - numbers 0-9
  8. uint8_t font[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
  9.  
  10. volatile uint8_t framebuffer[4];     // use to buffer contents of display
  11.  
  12. volatile uint8_t current_digit = 0;  // which digit is active now
  13.  
  14. ISR(TIMER0_OVF_vect)
  15. {
  16.   // the code for the interrupt service routine
  17.   PORTD = 0xff;                  // all segments off
  18.   current_digit += 1;            // step one digit
  19.   current_digit %= 4;            //    and keep between 0-3
  20.   PORTB = (1 << current_digit);
  21.   PORTD = ~font[current_digit];  // -- to be replaced! --
  22. }
  23.  
  24. void init(void)
  25. {
  26.   // we can collect all hardware initialization here
  27.   DDRB = 0b00001111;    // lower B-pins as output
  28.   DDRD = 0b11111111;    // all D-pins as output
  29.  
  30.  
  31.   // setting up TIMER0
  32.   TCCR0A = (0 << COM0A1) | (0 << COM0A0)   // we'll use PWM later
  33.          | (0 << COM0B1) | (0 << COM0B0)   // we'll use PWM later
  34.          | (_ << WGM01)  | (_ << WGM00);   // WGMxx sets the mode of the timer
  35.  
  36.   TCCR0B = (_ << WGM02)                    // WGMxx sets the mode of the timer
  37.          | (_ << CS02) | (_ << CS01) | (_ << CS00);  // clock prescaler
  38.  
  39.   // enable the TIMER0 OVERFLOW INTERRUPT
  40.   TIMSK0 = (0 << OCIE0B) | (0 << OCIE0A) | (1 << TOIE0);
  41.  
  42.   // don't forget to enable interrupts
  43.   sei();
  44. }
  45.  
  46. int main(void)
  47. {
  48.   init();
  49.   while (1)
  50.   {
  51.     // your specific code goes here
  52.   }
  53. }
Add Comment
Please, Sign In to add comment