From e486f6c6f73811f909299b54717bee72fe0ae7de Mon Sep 17 00:00:00 2001 From: lottaviano Date: Wed, 16 Mar 2011 13:06:13 +0000 Subject: [PATCH] Add seven segmend LED display driver (config files). This driver allows to display text on a seven segment LED display. Signed-off-by: Fabio Bizzi git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4778 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cfg/cfg_led_7seg.h | 79 +++++++++++++ bertos/hw/hw_led_7seg.h | 231 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 310 insertions(+) create mode 100644 bertos/cfg/cfg_led_7seg.h create mode 100644 bertos/hw/hw_led_7seg.h diff --git a/bertos/cfg/cfg_led_7seg.h b/bertos/cfg/cfg_led_7seg.h new file mode 100644 index 00000000..f195b579 --- /dev/null +++ b/bertos/cfg/cfg_led_7seg.h @@ -0,0 +1,79 @@ +/** + * \file cfg_led_7seg.h + * + * + * \brief Configuration file for led 7 segment display. + * + * \author Fabio Bizzi + * + * \addtogroup SevenSegDisplay 7 Segments LED Displays Driver + * \{ + * + */ + +#ifndef CFG_LED_7SEG_H +#define CFG_LED_7SEG_H + +/** + * Use a Common Cathode display. + * $WIZ$ type = "boolean" + */ +#define CONFIG_LED_7SEG_CCAT 0 + +/** + * Number of digit present in the LED display. + * $WIZ$ type = "int" + * $WIZ$ min = 1 + * $WIZ$ max = 8 + */ +#define CONFIG_LED_7SEG_DIGIT 4 + +/** + * Max lenght of the string to be displayed. + * $WIZ$ type = "int" + * $WIZ$ min = 16 + * $WIZ$ max = 255 + */ +#define CONFIG_LED_7SEG_STRLEN 255 + +/** + * Default scrolling speed (ms * CONFIG_LED_7SEG_RTIME). + * $WIZ$ type = "int" + */ +#define CONFIG_LED_7SEG_SSPEED 10 + +/** + * Default refresh time (ms). + * $WIZ$ type = "int" + */ +#define CONFIG_LED_7SEG_RTIME 5 + +#endif /* CFG_LED_7SEG_H */ + /** \} */ //defgroup drivers \ No newline at end of file diff --git a/bertos/hw/hw_led_7seg.h b/bertos/hw/hw_led_7seg.h new file mode 100644 index 00000000..41493235 --- /dev/null +++ b/bertos/hw/hw_led_7seg.h @@ -0,0 +1,231 @@ +/** + * \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 + * + * 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" + +/* + * 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) +{ +/* Set the display OFF */ +#ifdef CONFIG_LED_7SEG_CCAT +/* You have to implment it */ +/* Common Cathode */ +#else +/* You have to implment it */ +/* Common Anode */ +#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) +{ +#ifdef CONFIG_LED_7SEG_CCAT +/* Common Cathode */ +/* You have to implment it */ +#else +/* Common Anode */ +/* You have to implment it */ +#endif +} + +/** + * \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) +{ + /* Initialize PIN Direction to OUTPUT*/ + /* You have to implment it */ + /* Set the display OFF */ + sseg_off(); +} + +#endif /* HW_LED_7SEG_H */ + -- 2.25.1