Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* System Defines */
- #define F_CPU 8000000UL
- #define INND_TS56
- /* AVR Includes */
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- /* GCC Includes */
- #include <string.h>
- /* Library Includes */
- #include "seven_segment.h"
- #include "atmega328p.h"
- /* Program Includes */
- #include "pins.h"
- #define NUMBER_OF_SS_ENABLE_PINS 4
- #define NUMBER_OF_SS_SEGMENT_PINS 8
- void init(void);
- // [D0, D1, D2, D3].
- volatile uint8_t display_buffer[4] = {SS_1, SS_5 | SS_DEC, SS_2, SS_NEG}; // Test display data.
- void main(void)
- {
- init();
- TIFR2 |= (1 << TOV2); // Clear the overflow interrupt flag.
- TIMSK2 |= (1 << TOIE2); // Enable the timer overflow interrupt.
- TCCR2B |= (1 << CS10); // Start the timer with no prescaler.
- while(1)
- {
- }
- }
- void init(void)
- {
- // Set the seven segment pins as outputs:
- for (uint8_t i = 0; i < NUMBER_OF_SS_SEGMENT_PINS; i++)
- {
- pin_config_output(ss_segment_pins[i]);
- }
- // Set the display_enable_pins as outputs:
- for (uint8_t i = 0; i < NUMBER_OF_SS_ENABLE_PINS; i++)
- {
- pin_config_output(ss_segment_pins[i]);
- }
- _delay_ms(2000); // Sensor bootup delay.
- sei(); // Enable global interrupts.
- }
- // Display refresh ISR:
- ISR (TIMER2_OVF_vect)
- {
- static uint8_t display_counter;
- // Clear the previous display.
- pin_set_output_value(ss_enable_pins[display_counter], 0);
- // Output the segment signals:
- if (display_counter == 3)
- {
- display_counter = 0;
- }
- else
- {
- display_counter++;
- }
- for (uint8_t i = 0; i < NUMBER_OF_SS_SEGMENT_PINS; i++)
- {
- pin_set_output_value
- (
- ss_segment_pins[i],
- display_buffer[display_counter] & (1 << i)
- );
- }
- // Enable the digit's display.
- pin_set_output_value(ss_enable_pins[display_counter], 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement