Libraries and Example of mbed parallel bus using I2C port expanders

Dependencies:   HDSP253X mbed PCF8574_Bus

Committer:
wim
Date:
Fri Aug 26 20:35:11 2011 +0000
Revision:
5:38b853bb1afa
Parent:
3:3fbfdec782f4
Included Messages to Host

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 2:1dab1089c332 1 /* HDSP253X_Display - Intelligent 8 digit 5x7 LED matrix display
wim 2:1dab1089c332 2 *
wim 2:1dab1089c332 3 * Copyright (c) 2011 Wim Huiskamp
wim 2:1dab1089c332 4 * Modified software based on sourcecode by RAC 06/08/2008
wim 2:1dab1089c332 5 *
wim 2:1dab1089c332 6 * Released under the MIT License: http://mbed.org/license/mit
wim 2:1dab1089c332 7 *
wim 2:1dab1089c332 8 * version 0.2 Initial Release
wim 2:1dab1089c332 9 */
wim 2:1dab1089c332 10 #ifndef _HDSP253X_DISPLAY_H
wim 2:1dab1089c332 11 #define _HDSP253X_DISPLAY_H
wim 2:1dab1089c332 12 /*---------------------------------------------------------------------------*\
wim 2:1dab1089c332 13 | Original text by RAC 06/08/2008 has been modified to fix those parts of
wim 2:1dab1089c332 14 | the description which explain hardware or software that has been removed or
wim 2:1dab1089c332 15 | adapted in the new version.
wim 2:1dab1089c332 16 |
wim 2:1dab1089c332 17 | Description: Display driver and demonstrator for HDSP253X series intelligent
wim 2:1dab1089c332 18 | 8 character LED display modules. Options include adjusting
wim 2:1dab1089c332 19 | brightness and message blinking.
wim 2:1dab1089c332 20 | This software drives a single display module using 8 bit databus,
wim 2:1dab1089c332 21 | 5 bit addressbus and controlsignals. Note that this software
wim 2:1dab1089c332 22 | will drive all display devices in the series, including HDSP2530 Orange,
wim 2:1dab1089c332 23 | HDSP2531 Yellow, HDSP2532 red and HDSP2533 green devices. It will also
wim 2:1dab1089c332 24 | drive the smaller HDSP21XX series.
wim 2:1dab1089c332 25 |
wim 2:1dab1089c332 26 | The peripheral is connected to the following pins:
wim 2:1dab1089c332 27 | HDSP253X
wim 2:1dab1089c332 28 | - Reset (pin 1) to EnableBus.RESET
wim 2:1dab1089c332 29 | - Flash (pin 2) to AddressBus.A5
wim 2:1dab1089c332 30 | - Addr A0 (pin 3) to AddressBus.A0
wim 2:1dab1089c332 31 | - Addr A1 (pin 4) to AddressBus.A1
wim 2:1dab1089c332 32 | - Addr A2 (pin 5) to AddressBus.A2
wim 2:1dab1089c332 33 | - Addr A3 (pin 6) to AddressBus.A3
wim 2:1dab1089c332 34 | - Addr A4 (pin 10) to AddressBus.A4
wim 2:1dab1089c332 35 | - Clock select (pin 11) to VCC (Pull Up)
wim 2:1dab1089c332 36 | - Clock in/out (pin 12) to Not Connected
wim 2:1dab1089c332 37 | - Write (pin 13) to ControlBus.WR
wim 2:1dab1089c332 38 | - CE (Pin 14) to EnableBus.CSDISP
wim 2:1dab1089c332 39 | - VDD 5V (Pin 15)
wim 2:1dab1089c332 40 | - GND (supply) (Pin 16)
wim 2:1dab1089c332 41 | - TST (Pin 16) NC
wim 2:1dab1089c332 42 | - GND (logic) (Pin 18)
wim 2:1dab1089c332 43 | - Read (pin 19) to ControlBus.RD
wim 2:1dab1089c332 44 | - Data D0 (pin 20) to Databus.D0
wim 2:1dab1089c332 45 | - Data D1 (pin 21) to Databus.D1
wim 2:1dab1089c332 46 | - Data D2 (pin 25) to Databus.D2
wim 2:1dab1089c332 47 | - Data D3 (pin 26) to Databus.D3
wim 2:1dab1089c332 48 | - Data D4 (pin 27) to Databus.D4
wim 2:1dab1089c332 49 | - Data D5 (pin 28) to Databus.D5
wim 2:1dab1089c332 50 | - Data D6 (pin 29) to Databus.D6
wim 2:1dab1089c332 51 | - Data D7 (pin 30) to Databus.D7
wim 2:1dab1089c332 52 |
wim 2:1dab1089c332 53 | The peripheral is connected to the following pins:
wim 2:1dab1089c332 54 | HDSP211X
wim 2:1dab1089c332 55 | - Reset (pin 1) to EnableBus.RESET
wim 2:1dab1089c332 56 | - Flash (pin 2) to AddressBus.A5
wim 2:1dab1089c332 57 | - Addr A0 (pin 3) to AddressBus.A0
wim 2:1dab1089c332 58 | - Addr A1 (pin 4) to AddressBus.A1
wim 2:1dab1089c332 59 | - Addr A2 (pin 5) to AddressBus.A2
wim 2:1dab1089c332 60 | - Addr A3 (pin 6) to AddressBus.A3
wim 2:1dab1089c332 61 | - Addr A4 (pin 10) to AddressBus.A4
wim 2:1dab1089c332 62 | - Clock select (pin 11) to VCC (Pull Up)
wim 2:1dab1089c332 63 | - Clock in/out (pin 12) to Not Connected
wim 2:1dab1089c332 64 | - Write (pin 13) to ControlBus.WR
wim 2:1dab1089c332 65 | - VDD 5V (Pin 14)
wim 2:1dab1089c332 66 | - GND (supply) (Pin 15)
wim 2:1dab1089c332 67 | - GND (logic) (Pin 16)
wim 2:1dab1089c332 68 | - CE (Pin 17) to EnableBus.CSDISP
wim 2:1dab1089c332 69 | - Read (pin 18) to ControlBus.RD
wim 2:1dab1089c332 70 | - Data D0 (pin 19) to Databus.D0
wim 2:1dab1089c332 71 | - Data D1 (pin 20) to Databus.D1
wim 2:1dab1089c332 72 | - Data D2 (pin 23) to Databus.D2
wim 2:1dab1089c332 73 | - Data D3 (pin 24) to Databus.D3
wim 2:1dab1089c332 74 | - Data D4 (pin 25) to Databus.D4
wim 2:1dab1089c332 75 | - Data D5 (pin 26) to Databus.D5
wim 2:1dab1089c332 76 | - Data D6 (pin 27) to Databus.D6
wim 2:1dab1089c332 77 | - Data D7 (pin 28) to Databus.D7
wim 2:1dab1089c332 78 |
wim 2:1dab1089c332 79 | Details: All signals to the HDSP253X are pulled up by 10K resistors.
wim 2:1dab1089c332 80 | The device must be reset by pulsing Reset low with Chip Enable
wim 2:1dab1089c332 81 | set high. Other signals are don't cares during a reset. This
wim 2:1dab1089c332 82 | firmware meets these conditions, as long as the pullups are
wim 2:1dab1089c332 83 | correctly installed.
wim 2:1dab1089c332 84 |
wim 2:1dab1089c332 85 | Connecting the clock select and in/out lines to the CPU is optional,
wim 2:1dab1089c332 86 | and may be used for experimentation.
wim 2:1dab1089c332 87 | If using one display, the clock select should normally be pulled
wim 2:1dab1089c332 88 | up high, which results in the clock signal being an output.
wim 2:1dab1089c332 89 | This driver software does not currently control these signals.
wim 2:1dab1089c332 90 |
wim 2:1dab1089c332 91 | If using more than one display, the driver software will
wim 2:1dab1089c332 92 | require modification and extension. Multiple displays should
wim 2:1dab1089c332 93 | have reset, data, address, flash and read/write lines paralleled.
wim 2:1dab1089c332 94 | Each display requires a unique Chip Enable input, and the
wim 2:1dab1089c332 95 | driver software will need to select which display to access.
wim 2:1dab1089c332 96 | The first display should have clock select high, and its clock
wim 2:1dab1089c332 97 | output connected to the clock inputs on all the other displays;
wim 2:1dab1089c332 98 | these should have clock select low to input the clock signal.
wim 2:1dab1089c332 99 |
wim 2:1dab1089c332 100 | Calls to wait_ms() are used to meet the display timing specs
wim 2:1dab1089c332 101 | may need to be modified at higher CPU speeds.
wim 2:1dab1089c332 102 |
wim 2:1dab1089c332 103 |
wim 2:1dab1089c332 104 | Legalese: This software is FREEWARE, and you can adapt it for any
wim 2:1dab1089c332 105 | purpose whatsoever. I cannot be held responsible for any
wim 2:1dab1089c332 106 | loss, injury, damage or death caused by the use of this
wim 2:1dab1089c332 107 | software.
wim 2:1dab1089c332 108 |
wim 2:1dab1089c332 109 \*---------------------------------------------------------------------------*/
wim 2:1dab1089c332 110
wim 2:1dab1089c332 111 //Useful stuff to simplify porting of some third party software
wim 2:1dab1089c332 112 #include <stdarg.h>
wim 2:1dab1089c332 113 //#include "Utils.h"
wim 2:1dab1089c332 114
wim 2:1dab1089c332 115
wim 2:1dab1089c332 116 /*****************************************************************************/
wim 2:1dab1089c332 117 /********************* DEFINITIONS FOR HDSP253X DISPLAY ********************/
wim 2:1dab1089c332 118 /*****************************************************************************/
wim 2:1dab1089c332 119
wim 2:1dab1089c332 120 // Specific delays for display operation, assuming internal clocking
wim 2:1dab1089c332 121 // This may need to be lengthened if a significantly slower external clock is used
wim 2:1dab1089c332 122 #define HDSP253X_1TCY_WAIT_MS 1
wim 3:3fbfdec782f4 123 //#define HDSP253X_1TCY_WAIT_MS 10
wim 2:1dab1089c332 124 #define HDSP253X_RST_CLR_DELAY_MS 2 // delay AFTER issuing reset or clear
wim 2:1dab1089c332 125 #define HDSP253X_SELFTEST_WAIT_MS 6000 // duration of self test operation
wim 2:1dab1089c332 126
wim 2:1dab1089c332 127 // address values and masks for HDSP253X display access
wim 2:1dab1089c332 128 #define HDSP253X_ADDR_FLASH_BASE 0x00
wim 2:1dab1089c332 129 #define HDSP253X_ADDR_UDC_ADDRESS 0x20
wim 2:1dab1089c332 130 #define HDSP253X_ADDR_UDC_ROW_BASE 0x28
wim 2:1dab1089c332 131 #define HDSP253X_ADDR_CTRL_WORD 0x30
wim 2:1dab1089c332 132 #define HDSP253X_ADDR_CHAR_BASE 0x38
wim 2:1dab1089c332 133 // minimises address line power consumption through pullups
wim 2:1dab1089c332 134 #define HDSP253X_ADDR_LOW_POWER 0x3F
wim 2:1dab1089c332 135
wim 2:1dab1089c332 136 // control word masks for HDSP253X display
wim 2:1dab1089c332 137 #define HDSP253X_CTRL_BRIGHT_MASK 0x07
wim 2:1dab1089c332 138 #define HDSP253X_CTRL_FLASH_MASK 0x08
wim 2:1dab1089c332 139 #define HDSP253X_CTRL_BLINK_MASK 0x10
wim 2:1dab1089c332 140 #define HDSP253X_CTRL_STRESULT_MASK 0x20
wim 2:1dab1089c332 141 #define HDSP253X_CTRL_SELFTEST_MASK 0x40
wim 2:1dab1089c332 142 #define HDSP253X_CTRL_CLEAR_MASK 0x80
wim 2:1dab1089c332 143
wim 5:38b853bb1afa 144 // Masks for register read, Bit 7 not readable in the target hardware
wim 5:38b853bb1afa 145 #define HDSP253X_CTRL_MASK 0x7F
wim 5:38b853bb1afa 146
wim 5:38b853bb1afa 147
wim 2:1dab1089c332 148 // display brightness definitions, indicating percentage brightness
wim 2:1dab1089c332 149 #define HDSP253X_BRIGHT_100 0x00
wim 2:1dab1089c332 150 #define HDSP253X_BRIGHT_80 0x01
wim 2:1dab1089c332 151 #define HDSP253X_BRIGHT_53 0x02
wim 2:1dab1089c332 152 #define HDSP253X_BRIGHT_40 0x03
wim 2:1dab1089c332 153 #define HDSP253X_BRIGHT_27 0x04
wim 2:1dab1089c332 154 #define HDSP253X_BRIGHT_20 0x05
wim 2:1dab1089c332 155 #define HDSP253X_BRIGHT_13 0x06
wim 2:1dab1089c332 156 #define HDSP253X_BRIGHT_0 0x07
wim 2:1dab1089c332 157
wim 2:1dab1089c332 158 // miscellaneous definitions for HDSP253X display
wim 2:1dab1089c332 159 #define HDSP253X_NUM_CHARS 8
wim 2:1dab1089c332 160 #define HDSP253X_CHAR_MASK 0x7F
wim 2:1dab1089c332 161 #define HDSP253X_UDC_SEL 0x80
wim 2:1dab1089c332 162 #define HDSP253X_UDC_MASK 0x0F
wim 2:1dab1089c332 163 //#define HDSP253X_ASCII_UDC_CHARS 144
wim 2:1dab1089c332 164 //#define HDSP253X_POUND_CHAR 0x1E
wim 2:1dab1089c332 165
wim 2:1dab1089c332 166
wim 2:1dab1089c332 167 // default display brightness
wim 5:38b853bb1afa 168 #define HDSP253X_DEF_DISPLAY_BRIGHT HDSP253X_BRIGHT_100
wim 2:1dab1089c332 169
wim 2:1dab1089c332 170
wim 2:1dab1089c332 171 /** Create an HDSP253X_Display object connected to the proper busses
wim 2:1dab1089c332 172 *
wim 2:1dab1089c332 173 * @param PCF8574_DataBus data databus to connect to
wim 2:1dab1089c332 174 * @param PCF8574_AddressBus address addressbus to connect to
wim 2:1dab1089c332 175 * @param PCF8574_EnableBus enable enablebus to connect to
wim 2:1dab1089c332 176 * @param MBED_ControlBus control controlbus to connect to
wim 2:1dab1089c332 177 */
wim 2:1dab1089c332 178 class HDSP253X_Display {
wim 2:1dab1089c332 179 public:
wim 2:1dab1089c332 180 HDSP253X_Display(PCF8574_DataBus &databus, PCF8574_AddressBus &addressbus,
wim 2:1dab1089c332 181 PCF8574_EnableBus &enablebus, MBED_ControlBus &controlbus);
wim 2:1dab1089c332 182 void cls();
wim 2:1dab1089c332 183 void putc(char disp_char);
wim 2:1dab1089c332 184 // char getc();
wim 2:1dab1089c332 185
wim 2:1dab1089c332 186 void printf (char * format, ...);
wim 2:1dab1089c332 187 void locate(uint8_t column);
wim 2:1dab1089c332 188 void define_user_char(uint8_t udc_char_num, uint8_t row_data_1, uint8_t row_data_2,
wim 2:1dab1089c332 189 uint8_t row_data_3, uint8_t row_data_4, uint8_t row_data_5,
wim 2:1dab1089c332 190 uint8_t row_data_6, uint8_t row_data_7);
wim 2:1dab1089c332 191
wim 2:1dab1089c332 192 void set_char_flash_state(bool flash_state, uint8_t char_pos);
wim 2:1dab1089c332 193 void set_all_flash_states(uint8_t flash_bits);
wim 2:1dab1089c332 194 void set_brightness(uint8_t brightness);
wim 2:1dab1089c332 195 void set_blink_mode(bool enable);
wim 2:1dab1089c332 196 void set_flash_mode(bool enable);
wim 2:1dab1089c332 197 void reset();
wim 2:1dab1089c332 198 // void putudc(char byte);
wim 2:1dab1089c332 199 void start_self_test();
wim 2:1dab1089c332 200 bool finish_self_test();
wim 2:1dab1089c332 201
wim 2:1dab1089c332 202 protected:
wim 2:1dab1089c332 203 PCF8574_DataBus &_databus;
wim 2:1dab1089c332 204 PCF8574_AddressBus &_addressbus;
wim 2:1dab1089c332 205 PCF8574_EnableBus &_enablebus;
wim 2:1dab1089c332 206 MBED_ControlBus &_controlbus;
wim 2:1dab1089c332 207
wim 2:1dab1089c332 208 // int _row;
wim 2:1dab1089c332 209 int _column;
wim 2:1dab1089c332 210 void _write(uint8_t address, uint8_t data);
wim 2:1dab1089c332 211 uint8_t _read(uint8_t address);
wim 2:1dab1089c332 212 void _init();
wim 2:1dab1089c332 213 // void _display_ascii_char(char ascii_char, uint8_t char_pos);
wim 2:1dab1089c332 214 // void _display_udc_char(char udc_char, uint8_t char_pos);
wim 5:38b853bb1afa 215 // void _display_part_string(const char *disp_string, uint8_t start_pos, uint8_t end_pos);
wim 5:38b853bb1afa 216 // void _display_fixed_string(const char *disp_string, uint8_t start_pos);
wim 2:1dab1089c332 217
wim 2:1dab1089c332 218 };
wim 2:1dab1089c332 219
wim 2:1dab1089c332 220
wim 2:1dab1089c332 221 #endif
wim 2:1dab1089c332 222 /*****************************************************************************/
wim 2:1dab1089c332 223 /****************************** END OF FILE ********************************/
wim 2:1dab1089c332 224 /*****************************************************************************/
wim 2:1dab1089c332 225