msp430 lcd display code factory
This article is the continuation of our tutorial series on programming MSP430 using Code Composer Studio. Last tutorial was based on GPIO pins. This tutorial is about interfacing a display with MSP430, when it comes to display the 16*2 LCD Display,it is the first choice for any electronic hobbyist. Previously we have also interfaced LCD with MSP430 using Arduino IDE, in this tutorial, we will use the native Code Composer studio platform instead of using the Arduino IDE, this way as a designer, we get more flexibility.
It has an in-built IC hd44780 that can store the command and data passed to it. The LCD Module has about 16 pins. 8 of which are data pins, 4 of them are supply pins for backlight LED and the whole LCD module, 3 for controlling the operation, and 1 pin for contrast adjustment. The tutorial is based on the library created by Dennis Eichmann. It is very easy to use a library with separate functions to print different data types. It also has provisions to display the data in different forms with leading, blanked, and deleted zeroes. It is a pretty expansive and comprehensive library and is configurable to the different connections. Here, the header file is modified to accommodate an 8-pin parallel configuration for data communication.
A generic 16x2 Display has an inbuilt hd44780 IC(circled in red below), that can store the command and data passed to it. The LCD Module has about 16 pins. 8 of which are data pins, 4 of them are supply pins for backlight LED and the whole LCD module, 3 for controlling the operation, and 1 pin for contrast adjustment.
This LCD module is shown above versatile and uses minimum pins compared to other segmented LCDs. If you are curious to know how exactly all this works, you should check out the working of the 16x2 LCD display where we have already discussed how the LCD works in detail.
RS Pin: RS=1 will enable the data register in the LCD, which is used to write the values to the data register in LCD. RS=0 will enable the Instruction register of the LCD.
Enable pin: Negative edge-triggered; when the pin is changed from the HIGH state to LOW state, LCD is prompted to write to the data pins. Positive edge-triggered; when the pin is changed from the LOW state to HIGH state, LCD is prompted to read from the data pins.
The tutorial is based on the library created by Dennis Eichmann. It is very easy to use a library with separate functions to print different data types. It also has provisions to display the data in different forms with leading, blanked, and deleted zeroes. It is a pretty expansive and comprehensive library and is configurable to the different connections. Here, the header file is modified to accommodate an 8-pin parallel configuration for data communication. The library can be download from the below link, after downloading you follow the below steps to add the library to CCS.
In the properties dialog box of the hd44780 project and inside the include options for the MSP430 compiler, add the include folder in file the search path.
In the properties dialog box for the CCS_LCD project and in the file search path of MSP430 Linker tab, include the hd44780.lib located inside the debug folder of the hd44780 project. The debug folder is also included in the file search path.
void hd44780_timer_isr( void ):This is periodically called in the ISR of the Timer A. The Timer A is used to periodically do the LCD functions like clearing the screen, setting the cursor, and displaying the data. The function is to be used in the ISR. It returns nothing.
char * ch__string:The string to be written to the data buffer (inside the hd44780_timer_isrfunction). The data will be copied to the data register and instruction register of the LCD IC when the hd44780_timer_isris periodically called.
uint8_t hd44780_output_unsigned_16bit_value( uint16_t u16__value, uint8_t u8__leading_zero_handling, uint8_t u8__row, uint8_t u8__column, uint8_t u8__cr_lf ):The function will display the unsigned 16-bit value on the desired location of the LCD.
The anode of the LED backlight cannot be connected directly to a 5V supply. It should be connected to a resistance to minimize the current flow through the LCD Module. I have made my connections using a perf board to solder the LCD and then used jumper wires to connect the LCD with the MSP430 board, my set-up looks like this below but you can also simply use a breadboard to make your connections.
The complete code used in this project is given at the bottom of this page. The explanation of using the code is as follows. First, open the header file (hd44780.h) and include the microcontroller part number in the first part of the file.
Inbuilt timer is being used to display values periodically. Timer A is selected with SMCLK (1MHZ) as the clock source and continuous mode being the mode of operation.
Once you have your code compiled, you can upload it to the MSP430 board, as explained in the getting started with the MSP430 tutorial. If everything goes as expected, you should see your LCD display some contrast as shown below.
The LCD BoosterPack Text example is an application that demonstrates the use of the Kentec QVGA BoosterPack to display text on an LCD screen with a variety of different styling configurations. The user has the ability to display a variable text message of their choice and change the font size, font color, text position, and background color. This code example leverages the MSP432 Graphics Library that is shipped with the SimpleLink MSP432 SDK.
The LCD BoosterPack Text code example requires the standard configuration of an MSP-EXP432P401R LaunchPad with an attached BOOSTXL-CC2650 BoosterPack. Additionally, a Kentec QVGA BoosterPack must be stacked on top of the CC2650 BoosterPack. This hardware configuration is shown in the below image:
This code example has been tested with IAR Embeded Workbench 7.80.3 and Code Composer Studio v7.1. For more information on how to import this project into your IDE workspace and build/run, please refer to the main user’s guide.
Once the LCD BoosterPack Text code example starts, the LCD will turn to a black background with the text “Simplelink MSP432 SDK Bluetooth Plugin” displayed on the screen.
By default, this code example starts with BLE advertisement enabled indefinitely. Using your BLE client of choice, search for the “MSP432 LCD” device and connect:
The text string characteristic will change the value of the text that is displayed on the screen. From your client application, write any desired string value to this characteristic and the displayed text on the LCD will change:
The text color characteristic is a three byte value that controls the RGB value of the font display. The byte order is in the format of BB GG RR. For example, writing a value of 0000FF to the characteristic would change the text color to full red.
The X Position characteristic is the position of the beginning of the text string starting from the left side of the screen. The position is limited by the X resolution of the LCD screen (320) and a value from 0 to 320 can be used. A value of 160 will roughly put the text in the horizontal center of the screen.
The Y Position characteristic is the position of the top of the text starting from the top side of the screen. This value is limited by the Y resolution of the LCD screen (240) and a value from 0 to 240 can be used. A value of 120 will roughly put the text in the vertical center of the screen.
The text size characteristic changes the font size of the text on the screen. This code example has a total of eighteen different fonts (0 being the smallest, 17 being the largest). Changing the value of this characteristic will change the font size of the displayed string:
The last characteristic controls the background color of the LCD. The format of this characteristic is identical to the format of the text color characteristic (six byte BB GG RR value). Write to this value to change the background color:
Updating the firmware on the CC2650 BoosterPack uses the SBL libraries to invoke the CC2650’s bootloader and transfer the new firmware over serial. For LCD BoosterPack Text, the method to trigger this invocation is to hold down both S1 and S2 buttons on the LaunchPad for a duration of at least three seconds. Note that in order to trigger the firmware update, no active BLE device can be connected. Once S1 and S2 are held down for two seconds, LED2 on the LaunchPad will toggle bright blue to signal the BSL start:
MSP430F110, MSP430F1101, MSP430F1101A, MSP430F1111A, MSP430F112, MSP430F1121, MSP430F1121A, MSP430F1122, MSP430F1132, MSP430F122, MSP430F1222, MSP430F123, MSP430F1232, MSP430F133, MSP430F135, MSP430F147, MSP430F1471, MSP430F148, MSP430F1481, MSP430F149, MSP430F1491, MSP430F155, MSP430F156, MSP430F157, MSP430F1610, MSP430F1611, MSP430F1612, MSP430F167, MSP430F168, MSP430F169, MSP430F169-M
MSP430F2001, MSP430F2002, MSP430F2003, MSP430F2011, MSP430F2012, MSP430F2013, MSP430F2101, MSP430F2111, MSP430F2112, MSP430F2121, MSP430F2122, MSP430F2131, MSP430F2132, MSP430F2232, MSP430F2234, MSP430F2252, MSP430F2254, MSP430F2272, MSP430F2274, MSP430F233, MSP430F2330, MSP430F235, MSP430F2350, MSP430F2370, MSP430F2410, MSP430F2416, MSP430F2417, MSP430F2418, MSP430F2419, MSP430F247, MSP430F2471, MSP430F248, MSP430F2481, MSP430F249, MSP430F2491, MSP430F2616, MSP430F2617, MSP430F2618, MSP430F2619
MSP430G2001, MSP430G2101, MSP430G2102, MSP430G2111, MSP430G2112, MSP430G2113, MSP430G2121, MSP430G2131, MSP430G2132, MSP430G2152, MSP430G2153, MSP430G2201, MSP430G2202, MSP430G2203, MSP430G2210, MSP430G2211, MSP430G2212, MSP430G2213, MSP430G2221, MSP430G2230, MSP430G2231, MSP430G2232, MSP430G2233, MSP430G2252, MSP430G2253, MSP430G2302, MSP430G2303, MSP430G2312, MSP430G2313, MSP430G2332, MSP430G2333, MSP430G2352, MSP430G2353, MSP430G2402, MSP430G2403, MSP430G2412, MSP430G2413, MSP430G2432, MSP430G2433, MSP430G2444, MSP430G2452, MSP430G2453, MSP430G2513, MSP430G2533, MSP430G2544, MSP430G2553, MSP430G2744, MSP430G2755, MSP430G2855, MSP430G2955
MSP430F412, MSP430F412-FW, MSP430F413, MSP430F413-FW, MSP430F4132, MSP430F415, MSP430F415-FW, MSP430F4152, MSP430F417, MSP430F417-FW, MSP430F423, MSP430F4230, MSP430F423A, MSP430F423A, MSP430F425, MSP430F4250, MSP430F425A, MSP430F425A, MSP430F4260, MSP430F427, MSP430F4270, MSP430F427A, MSP430F427A, MSP430F435, MSP430F435-100P, MSP430F4351, MSP430F436, MSP430F436-100P, MSP430F4361, MSP430F437, MSP430F437-100P, MSP430F4371, MSP430F447, MSP430F448, MSP430F4481, MSP430F449, MSP430F4491, MSP430F4616, MSP430F46161, MSP430F4617, MSP430F46171, MSP430F4618, MSP430F46181, MSP430F4619, MSP430F46191, MSP430F47126, MSP430F47127, MSP430F47163, MSP430F47166, MSP430F47167, MSP430F47173, MSP430F47176, MSP430F47177, MSP430F47183, MSP430F47186, MSP430F47187, MSP430F47193, MSP430F47196, MSP430F47197, MSP430F477, MSP430F478, MSP430F4783, MSP430F4784, MSP430F479, MSP430F4793, MSP430F4794
MSP430FE423, MSP430FE4232, MSP430FE423A, MSP430FE423A, MSP430FE4242, MSP430FE425, MSP430FE4252, MSP430FE425A, MSP430FE425A, MSP430FE427, MSP430FE4272, MSP430FE427A, MSP430FE427A
MSP430FG4250, MSP430FG4260, MSP430FG4270, MSP430FG437, MSP430FG438, MSP430FG439, MSP430FG4616, MSP430FG4617, MSP430FG4618, MSP430FG4619, MSP430FG477, MSP430FG478, MSP430FG479
MSP430BT5190, MSP430F5131, MSP430F5132, MSP430F5151, MSP430F5152, MSP430F5171, MSP430F5172, MSP430F5212, MSP430F5213, MSP430F5214, MSP430F5217, MSP430F5218, MSP430F5219, MSP430F5222, MSP430F5223, MSP430F5224, MSP430F5227, MSP430F5228, MSP430F5229, MSP430F5232, MSP430F5234, MSP430F5237, MSP430F5239, MSP430F5242, MSP430F5244, MSP430F5247, MSP430F5249, MSP430F5252, MSP430F5253, MSP430F5254, MSP430F5255, MSP430F5256, MSP430F5257, MSP430F5258, MSP430F5259, MSP430F5304, MSP430F5308, MSP430F5309, MSP430F5310, MSP430F5324, MSP430F5325, MSP430F5326, MSP430F5327, MSP430F5328, MSP430F5329, MSP430F5333, MSP430F5335, MSP430F5336, MSP430F5338, MSP430F5340, MSP430F5341, MSP430F5342, MSP430F5358, MSP430F5359, MSP430F5418, MSP430F5418A, MSP430F5419, MSP430F5419A, MSP430F5435, MSP430F5435A, MSP430F5436, MSP430F5436A, MSP430F5437, MSP430F5437A, MSP430F5438, MSP430F5438A, MSP430F5500, MSP430F5501, MSP430F5502, MSP430F5503, MSP430F5504, MSP430F5505, MSP430F5506, MSP430F5507, MSP430F5508, MSP430F5509, MSP430F5510, MSP430F5513, MSP430F5514, MSP430F5515, MSP430F5517, MSP430F5519, MSP430F5521, MSP430F5522, MSP430F5524, MSP430F5525, MSP430F5526, MSP430F5527, MSP430F5528, MSP430F5529, MSP430F5630, MSP430F5631, MSP430F5632, MSP430F5633, MSP430F5634, MSP430F5635, MSP430F5636, MSP430F5637, MSP430F5638, MSP430F5658, MSP430F5659, MSP430SL5438A
MSP430F6433, MSP430F6435, MSP430F6436, MSP430F6438, MSP430F6458, MSP430F6459, MSP430F6630, MSP430F6631, MSP430F6632, MSP430F6633, MSP430F6634, MSP430F6635, MSP430F6636, MSP430F6637, MSP430F6638, MSP430F6658, MSP430F6659, MSP430F6720, MSP430F6720A, MSP430F6721, MSP430F6721A, MSP430F6723, MSP430F6723A, MSP430F6724, MSP430F6724A, MSP430F6725, MSP430F6725A, MSP430F6726, MSP430F6726A, MSP430F6730, MSP430F6730A, MSP430F6731, MSP430F6731A, MSP430F6733, MSP430F6733A, MSP430F6734, MSP430F6734A, MSP430F6735, MSP430F6735A, MSP430F6736, MSP430F6736A, MSP430F6745, MSP430F67451, MSP430F67451A, MSP430F6745A, MSP430F6746, MSP430F67461, MSP430F67461A, MSP430F6746A, MSP430F6747, MSP430F67471, MSP430F67471A, MSP430F6747A, MSP430F6748, MSP430F67481, MSP430F67481A, MSP430F6748A, MSP430F6749, MSP430F67491, MSP430F67491A, MSP430F6749A, MSP430F67621, MSP430F67621A, MSP430F67641, MSP430F67641A, MSP430F6765, MSP430F67651, MSP430F67651A, MSP430F6765A, MSP430F6766, MSP430F67661, MSP430F67661A, MSP430F6766A, MSP430F6767, MSP430F67671, MSP430F67671A, MSP430F6767A, MSP430F6768, MSP430F67681, MSP430F67681A, MSP430F6768A, MSP430F6769, MSP430F67691, MSP430F67691A, MSP430F6769A, MSP430F6775, MSP430F67751, MSP430F67751A, MSP430F6775A, MSP430F6776, MSP430F67761, MSP430F67761A, MSP430F6776A, MSP430F6777, MSP430F67771, MSP430F67771A, MSP430F6777A, MSP430F6778, MSP430F67781, MSP430F67781A, MSP430F6778A, MSP430F6779, MSP430F67791, MSP430F67791A, MSP430F6779A
MSP430FR2000, MSP430FR2032, MSP430FR2033, MSP430FR2100, MSP430FR2110, MSP430FR2111, MSP430FR2153, MSP430FR2155, MSP430FR2310, MSP430FR2311, MSP430FR2353, MSP430FR2355, MSP430FR2422, MSP430FR2433, MSP430FR2475, MSP430FR2476, MSP430FR2512, MSP430FR2522, MSP430FR2532, MSP430FR2533, MSP430FR2632, MSP430FR2633, MSP430FR2675, MSP430FR2676, MSP430FR2672, MSP430FR2673
MSP430FR5041, MSP430FR5043, MSP430FR50431, MSP430FR5720, MSP430FR5721, MSP430FR5722, MSP430FR5723, MSP430FR5724, MSP430FR5725, MSP430FR5726, MSP430FR5727, MSP430FR5728, MSP430FR5729, MSP430FR5730, MSP430FR5731, MSP430FR5732, MSP430FR5733, MSP430FR5734, MSP430FR5735, MSP430FR5736, MSP430FR5737, MSP430FR5738, MSP430FR5739, MSP430FR5847, MSP430FR58471, MSP430FR5848, MSP430FR5849, MSP430FR5857, MSP430FR5858, MSP430FR5859, MSP430FR5867, MSP430FR58671, MSP430FR5868, MSP430FR5869, MSP430FR5870, MSP430FR5872, MSP430FR58721, MSP430FR5887, MSP430FR5888, MSP430FR5889, MSP430FR58891, MSP430FR5922, MSP430FR59221, MSP430FR5947, MSP430FR59471, MSP430FR5948, MSP430FR5949, MSP430FR5957, MSP430FR5958, MSP430FR5959, MSP430FR5962, MSP430FR5964, MSP430FR5967, MSP430FR5968, MSP430FR5969, MSP430FR59691, MSP430FR5970, MSP430FR5972, MSP430FR59721, MSP430FR5986, MSP430FR5987, MSP430FR5988, MSP430FR5989, MSP430FR59891, MSP430FR5992, MSP430FR5994, MSP430FR59941
MSP430FR6005, MSP430FR6007, MSP430FR6037, MSP430FR60371, MSP430FR6035, MSP430FR6041, MSP430FR6043, MSP430FR60431, MSP430FR6045, MSP430FR6047, MSP430FR60471, MSP430FR6820, MSP430FR6822, MSP430FR68221, MSP430FR6870, MSP430FR6872, MSP430FR68721, MSP430FR6877, MSP430FR6879, MSP430FR68791, MSP430FR6887, MSP430FR6888, MSP430FR6889, MSP430FR68891, MSP430FR6920, MSP430FR6922, MSP430FR69221, MSP430FR6927, MSP430FR69271, MSP430FR6928, MSP430FR6970, MSP430FR6972, MSP430FR69721, MSP430FR6977, MSP430FR6979, MSP430FR69791, MSP430FR6987, MSP430FR6988, MSP430FR6989, MSP430FR69891
While e-paper is common among e-readers, there are very few, if any phones other than the MOTOFONE that exclusively use an e-paper display. [Steve] had one of these phones sitting around and thought it could be used to build a low-power clock. Since the bistable e-paper display can retain the currently active content even when power is removed, he would only need to update the clock once a minute, when the time changed.
Unfortunately for him, very little publicly-available documentation exists for the display controller Motorola used. To get an idea of how the display was driven, he had to sniff the SPI communications between the processor and the display. Once he had the basic commands down, he spent quite a bit of time figuring out how to activate the different segments of the display, due to what seems to be a rushed design process on Motorola’s part.
Now that [Steve] had reverse-engineered just about everything, he connected the phone to a TI MSP430 to drive the display. He programmed the LaunchPad to serve as a basic clock with great results, as you can see in the video below.
If you then click on the little down arrow on the right of the tab bar and select new tab from the pop up menu a new tab will appear. Give this tab a name such as my_code.c and click OK. The important thing in the name is the .c extension as this tells the complier that the code in this file is c code. You can also create .h files to store the header data.
The above blink code uses a software delay that is not efficient as the processor is continually decrementing i just to get a delay. A better approach to flashing an LED using a timer and interrupts to control the rate of blinking is given below.
To compile and upload the code to the microprocessor first make sure that the MSP430 Launch pad is plugged into one of the USB ports of your computer, then click the upload arrow. The red and green LEDs should now flash alternatively at around 6Hz.
Texas Instruments today announced its comprehensive ultra-low power FRAM microcontroller (MCU) platform with all the necessary hardware and software tools, and support for developers to reduce energy budgets, minimize product size and enable a battery-free world. TI’s new MSP430FR59x/69x FRAM MCU families with EnergyTrace++™ real-time power profiler and debugger range from 32 to 128 KB embedded FRAM. These MSP430™ MCUs are ideal for smart utility metering, wearable electronics, industrial and remote sensors, energy harvesting, home automation, data acquisition systems, the Internet of Things (IoT) and many more applications that require ultra-low power consumption, flexible memory options and smart analog integration.
TI’s innovative ultra-low-leakage (ULL) proprietary technology with embedded FRAM delivers the world’s lowest system power with active power of 100 uA/MHz, accurate-RTC standby power of 450 nA and industry-leading power performance across temperature range from -40 to 85 degrees Celsius. The new FRAM MCUs include a variety of smart analog peripherals, such as a differential input analog-to-digital converter (ADC) that consumes as little as 140 uA at 200 ksps and an enhanced scan interface for flow metering that can operate while the system is in standby, resulting in 10 times lower power. In addition, an integrated 8-mux LCD display and 256-bit Advanced Encryption Standard (AES) accelerator reduce power consumption, bill of materials and board space.
TI’s new EnergyTrace++ technology is the world’s first debug system that enables developers to analyze power consumption down to 5nA resolution in real-time for each peripheral. This allows engineers to take control of their power budget and optimize software to create the lowest energy product possible. This new technology is now available for both MSP430FR59x and MSP430FR69x MCU families and with the new low-cost MSP430FR5969 LaunchPad development kit.
Flexibility. FRAM has the unique ability to free developers from the traditional boundaries between code and data memory. Users no longer need to be confined to industry-standard flash-to-RAM ratios or pay a premium for increased RAM needs.
Ease of use. FRAM simplifies code development. Since FRAM does not require pre-erasure of segments and can be accessed at the bit-level, constant on-the-fly data logging is now possible. Wireless firmware updates are less complex, faster and lower energy.
Ease development with pin-to-pin compatibility and a scalable portfolio of 32 – 128KB devices within TI’s ultra-low power MSP430™ FRAM MCU product platform.
Extensive resources for developers include detailed migration guides and application notes to ease the migration from existing silicon to MSP430FR59x/69x MCUs.
The MSP430 series by Texas Instruments is a very popular low-power microcontroller which has many features yet is designed to run with very low power. TI sells individual chips, but the best way to prototype with the MSP430 is to use their launchpads (see below).
Note: This tutorial describes how to use the MSP430 with Code Composer Studio, an ASM/C/C++ based IDE. TI also has Energia, an Arduino-like development environment designed specifically for the launchpads. Please see this page for a tutorial on how to use Energia and the MSP430 launchpads.
Most likely, you want a board with the MSP430 installed, ready to hook into your system. TI offers a few MSP430 devices on a board, which they call a launchpad. Also, the launchpad has a built-in FET emulator that programs the MSP430.
The launchpads have an onboard FET to program the MSP430. Depending on the launchpad, the board will also create a virtual COM port for serial communication between the PC and UART via serial, and a small "flash-drive like" storage space for files. These separate lines for communication can operate simultaneously.
There are two important documents to reference: First, the device specific datasheet, found if you search for the device part number (e.g. MSP430F5529) on [[www.ti.com]]. This document lists the peripherals available on the device, but does not explain how to use the peripheral. Second, Family User"s Guide, under the User Guide section. The user guide explains peripheral registers and operation for all devices. For example, the MSP430G2553 has a USCI module for UART, I2C, SPI, but the MSP430G2452 has a USI module that also has SPI and I2C, but is more limited. The user guide has sections for both the USCI and USI so make sure to know which peripheral is on your device.
It is generally important to make your code as readable as possible, especially when you need to ask for help. This is particularly important for embedded programming where the code manipulates registers with cryptic names. To disable the watchdog timer, for example, it is possible to do the following:
However, you cannot easily tell what control bits are being set or cleared. Instead, use the macros in "msp430.h" and the device-specific library, e.g. "msp430g2553.h":
For any macro, hovering your cursor over the syntax will usually show the macro definition. Alternatively, look in the header files, msp430.h, and the device specific file.
By default, the watchdog timer on the MSP430 is enabled. It is a hardware timer that should be periodically reset in software, so that if the software hangs, the watchdog timer will reach max and reset the chip. You most likely want to disable the watchdog timer:
The MSP430 has a complex clock system designed to reduce power consumption. Instead of using a single clock to run the entire device, peripherals can run on slower clocks than the master clock running the CPU, to reduce power consumption. Certain clocks can also be turned off using the Low Power Modes to reduce power consumption. Note that details about the clock module depends highly on family and less on device, so check the user guide and datasheet.
The defining feature of the MSP430 is its low power modes. The low power modes shut down parts of the chip to reduce power usage, up to 500nA (In comparison with other brands that operate at a few milliamps). For example, the CPU is shut down until the UART interrupt is set, then the CPU performs some operation and is again shutdown.