Libraries and Example of mbed parallel bus using I2C port expanders
Dependencies: HDSP253X mbed PCF8574_Bus
Diff: HDSP253X_Display.cpp
- Revision:
- 3:3fbfdec782f4
- Parent:
- 2:1dab1089c332
- Child:
- 5:38b853bb1afa
--- a/HDSP253X_Display.cpp Sat Aug 20 12:49:44 2011 +0000 +++ b/HDSP253X_Display.cpp Sun Aug 21 19:42:48 2011 +0000 @@ -127,7 +127,8 @@ // Write data to the databus _databus.write(data); - + wait_ms(HDSP253X_1TCY_WAIT_MS); + // Set WR low, wait, then set high and wait _controlbus.WR(LOW); wait_ms(HDSP253X_1TCY_WAIT_MS); @@ -216,7 +217,6 @@ /*****************************************************************************/ #if(0) - /*---------------------------------------------------------------------------*\ | | Function: HDSP253X_display_ascii_char @@ -293,8 +293,8 @@ string_len = strlen(disp_string); // obtain length of string for (i = start_pos; (i < HDSP253X_NUM_CHARS) && ((i - start_pos) < string_len) && (i <= end_pos); i++) { - // write selected character to display at selected position - _write(HDSP253X_ADDR_CHAR_BASE + i, disp_string[i - start_pos]); + // write selected character to display at selected position + _write(HDSP253X_ADDR_CHAR_BASE + i, disp_string[i - start_pos]); } } @@ -310,7 +310,7 @@ | must NOT be used with read-only strings in program memory. | | Parameters: disp_string - fixed character string to display - | start_pos - starting position on the display (0 to 7) + | start_pos - starting position on the display (0 to 7) | | Returns: Nothing | @@ -324,22 +324,19 @@ // loop round, writing characters or spaces to whole display from start string_len = strlen(disp_string); // obtain length of string - for (i = 0; i < HDSP253X_NUM_CHARS; i++) - { - // work out whether to display a character or space - if ((i < start_pos) || ((i - start_pos) >= string_len)) - { + for (i = 0; i < HDSP253X_NUM_CHARS; i++) { + // work out whether to display a character or space + if ((i < start_pos) || ((i - start_pos) >= string_len)) { // out of string range, so select space character char_value = ' '; - } - else - { + } + else { // within string, so select string character char_value = disp_string[i - start_pos]; - } + } - // write selected character to display at selected position - _write(HDSP253X_ADDR_CHAR_BASE + i, char_value); + // write selected character to display at selected position + _write(HDSP253X_ADDR_CHAR_BASE + i, char_value); } } @@ -359,15 +356,23 @@ \*---------------------------------------------------------------------------*/ void HDSP253X_Display::printf (char * format, ...) { - char buffer[40]; + char display_string[64]; + int rv, string_len, i; va_list args; va_start (args, format); - int rv=vsprintf (buffer, format, args); -// ::printf("printing:'%s'\n", buffer); + + rv=vsprintf (display_string, format, args); + va_end (args); +// printf("printing:'%s'\n", display_string); // writeString (buffer); - va_end (args); -// return rv; + // loop round, writing characters + string_len = strlen(display_string); // obtain length of string + for (i = 0; i < string_len; i++) { + putc(display_string[i]); + }; + + // return rv; } @@ -387,13 +392,12 @@ | Returns: Nothing | \*---------------------------------------------------------------------------*/ +void HDSP253X_Display::putc(char disp_char) { -void HDSP253X_Display::putc(char disp_char) -{ // Write selected character to display at current position if ((disp_char & HDSP253X_UDC_SEL) == HDSP253X_UDC_SEL) { - // Write UDC character to display, code between 128-142 + // Write UDC character to display, code between 128-143 disp_char &= HDSP253X_UDC_MASK; // mask off unused bits disp_char |= HDSP253X_UDC_SEL; // add in top bit to specify UDC _write(HDSP253X_ADDR_CHAR_BASE + _column, disp_char); @@ -405,33 +409,31 @@ } // Incr and wrap around cursorposition - _column = (_column++) % HDSP253X_NUM_CHARS; + _column++; + _column = _column % HDSP253X_NUM_CHARS; } #if(0) - if (disp_char == '\n') { - _column = 0; - _row = (_row++) % HDSP253X_NUM_LINES; - } - else { - _putc(_column, _row, disp_char); - _column = (_column++) % HDSP253X_NUM_CHARS; - if (_column == 0) { - _row = (_row++) % HDSP253X_NUM_LINES; - } +//Testversion +void HDSP253X_Display::putc(char disp_char) { - -char HDSP253X_Display::getc() { - return -1; + // Write ASCII character, code between 0-127 + _write(HDSP253X_ADDR_CHAR_BASE + _column, disp_char); + + // Incr and wrap around cursorposition + _column++; + if (_column==HDSP253X_NUM_CHARS) _column=0; } - #endif - - +#if(0) +char HDSP253X_Display::getc() { + return -1; +} +#endif /*---------------------------------------------------------------------------*\ | @@ -445,8 +447,8 @@ | \*---------------------------------------------------------------------------*/ -void HDSP253X_Display::locate(uint8_t column) -{ +void HDSP253X_Display::locate(uint8_t column) { + // _row = row % HDSP253X_NUM_ROWS; _column = column % HDSP253X_NUM_CHARS; } @@ -467,8 +469,8 @@ | \*---------------------------------------------------------------------------*/ -void HDSP253X_Display::cls(void) -{ +void HDSP253X_Display::cls(void) { + uint8_t disp_data; // Read in control word, modify and write back out @@ -497,8 +499,8 @@ | \*---------------------------------------------------------------------------*/ -void HDSP253X_Display::set_brightness(uint8_t brightness) -{ +void HDSP253X_Display::set_brightness(uint8_t brightness) { + uint8_t ctrl_data; // Read in control word, modify and write back out @@ -536,8 +538,8 @@ | \*---------------------------------------------------------------------------*/ -void HDSP253X_Display::start_self_test(void) -{ +void HDSP253X_Display::start_self_test(void) { + // Reset the display to ensure it is ready for the self test reset(); @@ -564,8 +566,7 @@ | \*---------------------------------------------------------------------------*/ -bool HDSP253X_Display::finish_self_test(void) -{ +bool HDSP253X_Display::finish_self_test(void) { uint8_t ctrl_data; bool result; @@ -597,18 +598,15 @@ | \*---------------------------------------------------------------------------*/ -void HDSP253X_Display::set_blink_mode(bool enable) -{ +void HDSP253X_Display::set_blink_mode(bool enable) { uint8_t ctrl_data; // read in control word, modify and write back out ctrl_data = _read(HDSP253X_ADDR_CTRL_WORD); - if (enable) - { + if (enable) { ctrl_data |= HDSP253X_CTRL_BLINK_MASK; } - else - { + else { ctrl_data &= ~HDSP253X_CTRL_BLINK_MASK; } _write(HDSP253X_ADDR_CTRL_WORD, ctrl_data); @@ -628,18 +626,15 @@ | \*---------------------------------------------------------------------------*/ -void HDSP253X_Display::set_flash_mode(bool enable) -{ +void HDSP253X_Display::set_flash_mode(bool enable) { uint8_t ctrl_data; // read in control word, modify and write back out ctrl_data = _read(HDSP253X_ADDR_CTRL_WORD); - if (enable) - { + if (enable) { ctrl_data |= HDSP253X_CTRL_FLASH_MASK; } - else - { + else { ctrl_data &= ~HDSP253X_CTRL_FLASH_MASK; } _write(HDSP253X_ADDR_CTRL_WORD, ctrl_data); @@ -696,8 +691,7 @@ | \*---------------------------------------------------------------------------*/ -void HDSP253X_Display::set_char_flash_state(bool flash_state, uint8_t char_pos) -{ +void HDSP253X_Display::set_char_flash_state(bool flash_state, uint8_t char_pos) { // Write out the new flash state to the flash RAM _write(HDSP253X_ADDR_FLASH_BASE + char_pos, flash_state); }