MSP430 HD44780 Controller Software

From wiki
Jump to navigation Jump to search

The following page is dedicated to hosting a simple interface for the HD44780 display controller written in C for the TI MSP430 family of microcontrollers. Specifically, this library was written with the MSP430 Launchpad (msp430g2231) in mind but it should work with any microcontroller in that family without modification.

Get The Code

Download the code (including a pre-compiled example) here: msp430-hd44780.tar.bz2


  1. The microntroller's main clock should be running at 16MHz or less (the library is designed with 16MHz as the wosrt-case clock frequency).
  2. You must use the controller in 4-bit mode, which means the least significant data lines don't get connected. This is a bit slower, but makes better use of the limited pins on the smaller MSP430 devices.
  3. All 7 lines coming from the display controller (DB7-DB4, RS, RW, and EN) must be connected to the same port on the microcontroller.
  4. The four data lines must be connected in order, in a contiguous set of pins. For example: DB7=P1.6, DB6=P1.5, DB5=P1.4, DB4=P1.3
  5. The following must be #define'd in your code in order to use this library (do this in hd44780_config.h):
    • HD44780_PORT: The OUT register of the port that the display is connected to (eg. P1OUT)
    • HD44780_PORTDIR: The port's DIR register (eg. P1DIR)
    • HD44780_PORTIN: The port's IN register (eg. P1IN)
    • HD44780_RS: The pin that's connected to RS (eg. BIT0)
    • HD44780_RW: The pin that's connected to RW (eg. BIT1)
    • HD44780_EN: The pin that's connected to EN (eg. BIT2)
    • HD44780_BUSY: The pin that's connected to DB7 (eg. for P1.7, use BIT7)
    • HD44780_DATA: A mask containing all the data lines, for example: If DB7 is connected to P1.7, use (BIT7|BIT6|BIT5|BIT4)
    • HD44780_DATA_OFFSET: The data lines' offset relative to DB0 (eg. for the example shown in HD44780_DATA, this must be set to 4)

List of Functions in hd44780.h

This library only has 5 functions, but even so you should be able to do almost any operation that the controller supports.

void hd44780_init(uint8_t);

HD44780 initialization routine, must be run before any other hd44780_* functions. This function clears the display so there's no need to do so after calling this function.

The argument sets the number of lines on your display. It can be one of two values, either HD44780_CMD_1_LINE_MODE or HD44780_CMD_2_LINE_MODE. Once initialized, the HD44780_CMD_*_LINE_MODE commands should _not_ be issued again (as specified in the datasheet). */

void hd44780_send_command(uint8_t);

Send the HD44780 a command. Commands are #define'd above (HD44780_CMD_*). Note: There is no need to check the busy flag before sending commands, this is done for you in the function.

void hd44780_write_char(char);

Write a single character to the display. Note: This function waits for the busy flag for you.

void hd44780_write_string(char*);

Write a null-terminated string of characters to the display. This function simply loops over your string writing one character at a time using hd44780_write_char().

uint8_t hd44780_get_busy_flag();

Returns the busy flag as reported by the HD44780. Returns either 0x80 (busy) or 0x00 (not busy).