Advertisement
Guest User

Untitled

a guest
May 15th, 2022
18
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. /* System Defines */
  4. #define F_CPU 8000000UL
  5. #define INND_TS56
  6.  
  7. /* AVR Includes */
  8. #include <avr/io.h>
  9. #include <avr/interrupt.h>
  10. #include <util/delay.h>
  11. /* GCC Includes */
  12. #include <string.h>
  13. /* Library Includes */
  14. #include "seven_segment.h"
  15. #include "atmega328p.h"
  16. /* Program Includes */
  17. #include "pins.h"
  18.  
  19. #define NUMBER_OF_SS_ENABLE_PINS 4
  20. #define NUMBER_OF_SS_SEGMENT_PINS 8
  21.  
  22.  
  23. void init(void);
  24. // [D0, D1, D2, D3].
  25. volatile uint8_t display_buffer[4] = {SS_1, SS_5 | SS_DEC, SS_2, SS_NEG};   // Test display data.
  26.  
  27.  
  28.  
  29. void main(void)
  30. {
  31.     init();
  32.  
  33.     TIFR2 |= (1 << TOV2);   // Clear the overflow interrupt flag.
  34.     TIMSK2 |= (1 << TOIE2); // Enable the timer overflow interrupt.
  35.     TCCR2B |= (1 << CS10);  // Start the timer with no prescaler.
  36.  
  37.     while(1)
  38.     {
  39.     }
  40. }
  41.  
  42. void init(void)
  43. {
  44.     // Set the seven segment pins as outputs:
  45.     for (uint8_t i = 0; i < NUMBER_OF_SS_SEGMENT_PINS; i++)
  46.     {
  47.         pin_config_output(ss_segment_pins[i]);
  48.     }
  49.     // Set the display_enable_pins as outputs:
  50.     for (uint8_t i = 0; i < NUMBER_OF_SS_ENABLE_PINS; i++)
  51.     {
  52.         pin_config_output(ss_segment_pins[i]);
  53.     }
  54.    
  55.     _delay_ms(2000);    // Sensor bootup delay.
  56.  
  57.     sei();  // Enable global interrupts.
  58. }
  59.  
  60. // Display refresh ISR:
  61. ISR (TIMER2_OVF_vect)
  62. {
  63.     static uint8_t display_counter;
  64.  
  65.     // Clear the previous display.
  66.     pin_set_output_value(ss_enable_pins[display_counter], 0);
  67.     // Output the segment signals:
  68.     if (display_counter == 3)
  69.     {
  70.         display_counter = 0;
  71.     }
  72.     else
  73.     {
  74.         display_counter++;
  75.     }
  76.     for (uint8_t i = 0; i < NUMBER_OF_SS_SEGMENT_PINS; i++)
  77.     {
  78.         pin_set_output_value
  79.         (
  80.             ss_segment_pins[i],
  81.             display_buffer[display_counter] & (1 << i)
  82.         );
  83.     }
  84.     // Enable the digit's display.
  85.     pin_set_output_value(ss_enable_pins[display_counter], 1);
  86.  
  87. }
  88.  
  89.  
Advertisement
RAW Paste Data Copied
Advertisement