From c3bbbdefb9f72672c6717285bc94304a7eb97347 Mon Sep 17 00:00:00 2001 From: lottaviano Date: Wed, 16 Mar 2011 13:33:13 +0000 Subject: [PATCH] Add seven segment LED display implementation for Arduino Mega. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4780 38d2e660-2303-0410-9eaa-f027e97ec537 --- boards/arduino-mega/hw/hw_led_7seg.h | 313 +++++++++++++++++++++++++++ 1 file changed, 313 insertions(+) create mode 100644 boards/arduino-mega/hw/hw_led_7seg.h diff --git a/boards/arduino-mega/hw/hw_led_7seg.h b/boards/arduino-mega/hw/hw_led_7seg.h new file mode 100644 index 00000000..8962eb31 --- /dev/null +++ b/boards/arduino-mega/hw/hw_led_7seg.h @@ -0,0 +1,313 @@ +/** + * \file hw_led_7seg.h + * + * + * \brief led 7 segment display low-level + * + * This file has the functions that must be + * implemented to drive the 7 segments display by your + * hardware + * + * \author Fabio Bizzi + * + * \addtogroup SevenSegDisplay 7 Segments LED Displays Driver + * \{ + * + * Example implementation for AtMEGA 1280 + * (Arduino MEGA) with a 4 digit display. + * We use PORTA to connect the 8 pins of + * the 7 segments display and 4 bit of + * PORTC to select which digit of the + * display we have to write on. + * + * \code + * 7 Seg LED Pin + * ---------------- + * LED SEGMENT + * ---------------- + * DP G F E D C B A + * 7 6 5 4 3 2 1 0 + * ---------------- + * PORT A Pin + * ---------------- + * + * 7 Seg Display Selection + * ---------------- + * Display Nr. + * ---------------- + * N N N N 3 2 1 0 + * 7 6 5 4 3 2 1 0 + * ---------------- + * PORT C Pin + * ---------------- + * \endcode + * + * The implementation of the sseg_on procedure that set the PROPER PIN of PORT C + * to enable the requested digit of the display, after write the encoded character + * to PORT A + * + * \code + * + * INLINE void sseg_on(uint8_t dgt, uint8_t n_dgt) + * { + * switch (n_dgt) + * { + * //Common Cathode + * #ifdef CONFIG_LED_7SEG_CCAT + * + * case 0: + * PORTC &= ~(BV(PORTC1) | BV(PORTC2) | BV(PORTC3)); + * PORTC |= BV(PORTC0); + * break; + * case 1: + * PORTC &= ~(BV(PORTC0) | BV(PORTC2) | BV(PORTC3)); + * PORTC |= BV(PORTC1); + * break; + * case 2: + * PORTC &= ~(BV(PORTC0) | BV(PORTC1) | BV(PORTC3)); + * PORTC |= BV(PORTC2); + * break; + * case 3: + * PORTC &= ~(BV(PORTC0) | BV(PORTC1) | BV(PORTC2)); + * PORTC |= BV(PORTC3); + * break; + * + * //Common Anode + * #else + * + * case 0: + * PORTC |= (BV(PORTC1) | BV(PORTC2) | BV(PORTC3)); + * PORTC &= ~(BV(PORTC0)); + * break; + * case 1: + * PORTC |= (BV(PORTC0) | BV(PORTC2) | BV(PORTC3)); + * PORTC &= ~(BV(PORTC1)); + * break; + * case 2: + * PORTC |= (BV(PORTC0) | BV(PORTC1) | BV(PORTC3)); + * PORTC &= ~(BV(PORTC2)); + * break; + * case 3: + * PORTC |= (BV(PORTC0) | BV(PORTC1) | BV(PORTC2)); + * PORTC &= ~(BV(PORTC3)); + * break; + * + * #endif + * + * } + * //Write the charater + * PORTA = dgt; + * } + * + * \endcode + * + * The implementation of the sseg_init procedure that set the DIRECTION of PORT C + * and PORT A to output + * + * \code + * + * INLINE void sseg_init(void) + * { + * //Initialize PIN Direction to OUTPUT + * DDRA = 0xFF; + * DDRC |= (BV(DDC0) | BV(DDC1) | BV(DDC2) | BV(DDC3)); + * //Set the display OFF + * SSEG_OFF(); + * } + * + * \endcode + * + * The implementation of the sseg_off procedure that set the reset PORT A + * to clean the display and turn off all the pin of PORT C that drive the + * display's digits + * + * \code + * + * INLINE void sseg_off(void) + * { + * //Set the display OFF + * //Common Cathode + * #ifdef CONFIG_LED_7SEG_CCAT + * PORTA = 0x00; + * PORTC &= ~(BV(PORTC0) | BV(PORTC1) | BV(PORTC2) | BV(PORTC3)); + * //Common Anode + * #else + * PORTA = 0xFF; + * PORTC |= (BV(PORTC0) | BV(PORTC1) | BV(PORTC2) | BV(PORTC3)); + * #endif + * + * } + * + * \endcode + * + */ + +#ifndef HW_LED_7SEG_H +#define HW_LED_7SEG_H + +#include "cfg/cfg_led_7seg.h" +#include "cfg/cfg_arch.h" +#include +#include +#include +#include + +/* + * INLINE HW Functions + */ + +/** + * \brief Clean the display + * + * This is the procedure that clean the display in HW mode. + * you have to write it according with your hardware and micro. + */ +INLINE void sseg_off(void) +{ +/* Example implementation for AtMEGA 1280 + * (Arduino MEGA) with a 4 digit display. + * We use PORTA to connect the 8 pins of + * the 7 segments display and 4 bit of + * PORTC to select which digit of the + * display we have to write on. + */ + + /* Set the display OFF */ +/* Common Cathode */ +#ifdef CONFIG_LED_7SEG_CCAT + PORTA = 0x00; + PORTC &= ~(BV(PORTC0) | BV(PORTC1) | BV(PORTC2) | BV(PORTC3)); +/* Common Anode */ +#else + PORTA = 0xFF; + PORTC |= (BV(PORTC0) | BV(PORTC1) | BV(PORTC2) | BV(PORTC3)); +#endif +} + +/** + * \brief writes the character to the single digit of the display + * + * This is the procedure that writes the character to the single digit + * of the display, you have to write it according with your hardware and micro. + * + * \param dgt the character that has to be displayed + * \param n_dgt the digit where to disply the character of the display's digits. + */ +INLINE void sseg_on(uint8_t dgt, uint8_t n_dgt) +{ +/* Example implementation for AtMEGA 1280 + * (Arduino MEGA) with a 4 digit display. + * We use PORTA to connect the 8 pins of + * the 7 segments display and 4 bit of + * PORTC to select which digit of the + * display we have to write on. + * + * 7 Seg LED Pin + * ---------------- + * DP G F E D C B A + * 7 6 5 4 3 2 1 0 + * ---------------- + * PORT A Pin + * + */ + switch (n_dgt) + { +/* Common Cathode */ +#ifdef CONFIG_LED_7SEG_CCAT + + case 0: + PORTC &= ~(BV(PORTC1) | BV(PORTC2) | BV(PORTC3)); + PORTC |= BV(PORTC0); + break; + case 1: + PORTC &= ~(BV(PORTC0) | BV(PORTC2) | BV(PORTC3)); + PORTC |= BV(PORTC1); + break; + case 2: + PORTC &= ~(BV(PORTC0) | BV(PORTC1) | BV(PORTC3)); + PORTC |= BV(PORTC2); + break; + case 3: + PORTC &= ~(BV(PORTC0) | BV(PORTC1) | BV(PORTC2)); + PORTC |= BV(PORTC3); + break; + +/* Common Anode */ +#else + + case 0: + PORTC |= (BV(PORTC1) | BV(PORTC2) | BV(PORTC3)); + PORTC &= ~(BV(PORTC0)); + break; + case 1: + PORTC |= (BV(PORTC0) | BV(PORTC2) | BV(PORTC3)); + PORTC &= ~(BV(PORTC1)); + break; + case 2: + PORTC |= (BV(PORTC0) | BV(PORTC1) | BV(PORTC3)); + PORTC &= ~(BV(PORTC2)); + break; + case 3: + PORTC |= (BV(PORTC0) | BV(PORTC1) | BV(PORTC2)); + PORTC &= ~(BV(PORTC3)); + break; + +#endif + } + /* Write the charater */ + PORTA = dgt; +} + +/** + * \brief initalize the HW regsiters + * + * This is the procedure that initalize the HW regsiters. + * you have to write it according with your hardware and micro. + */ +INLINE void sseg_init(void) +{ +/* Example implementation for AtMEGA 1280 + * (Arduino MEGA) with a 4 digit display. + * We use PORTA to connect the 8 pins of + * the 7 segments display and 4 bit of + * PORTC to select which digit of the + * display we have to write on. + */ + + /* Initialize PIN Direction to OUTPUT*/ + DDRA = 0xFF; + DDRC |= (BV(DDC0) | BV(DDC1) | BV(DDC2) | BV(DDC3)); + /* Set the display OFF */ + sseg_off(); +} + +#endif /* HW_LED_7SEG_H */ + + /** \} */ //defgroup drivers \ No newline at end of file -- 2.25.1