This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Writing to LCD from MSP430

Other Parts Discussed in Thread: MSP430F169

Hello, I'm working for the first time with the MSP430 (MSP430FW427A to be exact) and my previous experience with microcontrollers comes from using the Basic Atom-40 microcontroller(houses a PIC chip and programs by PBASIC). The LCD write commands are very simple in PBASIC, such is not hte case for the MSP430 and C. I'm not really sure where to get started. I have some sample programs that write to an LCD display and have gone through the user guide of the chip but I haven't really found anything pointing me in the right direction. Anyone here have a link or some info that could help me as I learn to write to LCD displays?

Any help is appreciated.


Thanks,

  • I don't know about the PIC based LCD and PBasic. Maybe PBasic already includes library functions (disguised as basic commands) for handling the LCD.

    The MSP itself has no embedded library functions for the LCD access. You have to do it on your own of find code from someone else who has already done it.

    One starting point might be the applicaiton notes database from the TI website. While the family users guide and the device datasheet tell you 'what is', the applicaiton notes tell you 'how to'. After a quick look, I found the following: http://www.ti.com/litv/pdf/slaa293 . it describes how to connect two MSPs for driving larger displays than 40 segments (or 160 with multiplexing). It goes beyond the basic stuff, but maybe you can extract some ideas from teh code. The source code is found at http://www.ti.com/litv/zip/slaa293 .

    Basically, the MSP LCD driver has an array of 20 bytes (160 bit) which holds the information of which segment to set or not on the LCD. A segment is one dot, line or whatever. Since 160 (or even 40 on a non-multiplexed display) isn't much, it is mainly designed for 7 segment displays (numbers). Bit 0 and 4 of each of the 20 bytes holds the information of two segments for Multiplex phase 1 (or static displays), bits 1 and 5 for multiplex phase 2 etc.

    I wonder why TI has chosen to make things so complex, I had preferred getting 8 bits for phase 0 on byte 0 etc, so you can just write one complete digits segment combination ito one byte. But maybe it's easier to handle on silicon.

    Nevertheless, you need to write a function that takes e.g. value and position and calculates 1) the segment combination for the value and 2) writes the calculated values into the proper bits of the 20 registers. Then you need another function that initializes and sets up the controller (frequency, multiplex mode, drive strength, contrast etc.). Maybe you'll find something in the above source code.

    It's not easy to start up with the TI processors, as they don't have built-in support for all their hardware and TI does not provide a library collection. But I prefer doing things on my own. besides the challenge, prebuilt libraries tend to be much larger than required for a certain project, and when using many of the hardware modules, the size of the libraries can easily exceed the devices flash memory. After all it's not a PC with GB of Ram and aHD to swap additional virutal memory in and out.

     

  • Hello,

    First of all, tell us what kind of LCD you have in mind. I have started from alphanumeric LCD with built in driver. A lot of code source available for this. I was using the one from Olimex.com (MSP430F169 board sourcecode). But maybe you are starting from different LCD type.

  • Grzegorz Latocha said:

    Hello,

    First of all, tell us what kind of LCD you have in mind. I have started from alphanumeric LCD with built in driver. A lot of code source available for this. I was using the one from Olimex.com (MSP430F169 board sourcecode). But maybe you are starting from different LCD type.

    Hello Grzegorz,

    As of right now I'm using the Softbaugh development board ESW427. It comes equipped with a SBLCDA4 for testing purposes. It's 7.1 segment, 4mux.

     

  • Jens-Michael Gross said:

    I don't know about the PIC based LCD and PBasic. Maybe PBasic already includes library functions (disguised as basic commands) for handling the LCD.

    The MSP itself has no embedded library functions for the LCD access. You have to do it on your own of find code from someone else who has already done it.

    One starting point might be the applicaiton notes database from the TI website. While the family users guide and the device datasheet tell you 'what is', the applicaiton notes tell you 'how to'. After a quick look, I found the following: http://www.ti.com/litv/pdf/slaa293 . it describes how to connect two MSPs for driving larger displays than 40 segments (or 160 with multiplexing). It goes beyond the basic stuff, but maybe you can extract some ideas from teh code. The source code is found at http://www.ti.com/litv/zip/slaa293 .

    Basically, the MSP LCD driver has an array of 20 bytes (160 bit) which holds the information of which segment to set or not on the LCD. A segment is one dot, line or whatever. Since 160 (or even 40 on a non-multiplexed display) isn't much, it is mainly designed for 7 segment displays (numbers). Bit 0 and 4 of each of the 20 bytes holds the information of two segments for Multiplex phase 1 (or static displays), bits 1 and 5 for multiplex phase 2 etc.

    I wonder why TI has chosen to make things so complex, I had preferred getting 8 bits for phase 0 on byte 0 etc, so you can just write one complete digits segment combination ito one byte. But maybe it's easier to handle on silicon.

    Nevertheless, you need to write a function that takes e.g. value and position and calculates 1) the segment combination for the value and 2) writes the calculated values into the proper bits of the 20 registers. Then you need another function that initializes and sets up the controller (frequency, multiplex mode, drive strength, contrast etc.). Maybe you'll find something in the above source code.

    It's not easy to start up with the TI processors, as they don't have built-in support for all their hardware and TI does not provide a library collection. But I prefer doing things on my own. besides the challenge, prebuilt libraries tend to be much larger than required for a certain project, and when using many of the hardware modules, the size of the libraries can easily exceed the devices flash memory. After all it's not a PC with GB of Ram and aHD to swap additional virutal memory in and out.

     

    Thanks for the response Jens-Michael. It is very informative and helpful. PBasic does indeed include library functions disguised as commands in order to drive the LCD. Makes it really easy needless to say; as opposed to working with the MSP430. I will check out those application notes and that source code. Thanks for the help.

  • So, if you have a segment LCD connected to the LCD controller in MSP430 then you just need to look at the schematic and write to the corresponding memory. How to setup the LCD controller you will find in the F4xx family user guide. After all it is only one control register.

     

    Now I have found the LCD demo on the Softbaud website:

    http://www.softbaugh.com/ProductPage.cfm?strPartNo=ESW427#Download

     

    good luck

  • Grzegorz Latocha said:

    So, if you have a segment LCD connected to the LCD controller in MSP430 then you just need to look at the schematic and write to the corresponding memory. How to setup the LCD controller you will find in the F4xx family user guide. After all it is only one control register.

     

    Now I have found the LCD demo on the Softbaud website:

    http://www.softbaugh.com/ProductPage.cfm?strPartNo=ESW427#Download

     

    good luck

    Yes i have that code and have ran the program on the board. What I was looking for something explaining what the code is doing exactly. I'm very new to this and the documentation is at a minimum. Any place where there are C commands for MSP430 and their explanations?

  • There are no 'C' commands other than the commands defined in the C standard.

    Contrary to basic, where there is no standard at all and everyone can call his collection of commands 'basic', C is a standardized programming language that offers everything you nee to structurize your program and the data you want to use. And while Basic is most often an interpreter language (tha tmeans, your program is a script that is interpreted at runtime), C is compiled and then executed on processor hardware level. A C-Program by itself can be compiled for every processor where a C compiler exists.

    IF it does what you want, however, depends on some other things:

    There is a standard library defined that is usually provided for every C compiler and target processos. This library contains some (often but not always heavily optimized) functions. These functions are not more than standard C code itself, as you could write yourself more or less easily, but provide a base of often-required functionality, such as converting a binary value to a text, comparing two strings and such. This library should be available for your compiler too. Note that this library belongs to the compiler (and often, teh source code of the included functions is also available), even if specifically written for the target processor (as the compiler is too).

    There might be more than this standard library available for yor compiler/processor combo. Either from the processor manufavturer, or from the OS manufacturer (if you decide to use one) or from other users. Still this is optional and just more 'C' code (or assembly code, as C supports being linked with machine-level assembly code).

    The MSP itself is a dumb thing. Powerful, but with no integreted code (other than the bootloader). Everything it shall do must be implemented by your program, either directly through your code or by additinal libraries that _you_ link to your code (as if they were part of your code). Only the standard library is usually handled automatically.

    In C, there is another element in addition to your code: header files. The compiler usually compiles each code file (*.c) separately. To tell the compiler, that other code files contain functions you can use, there are header files (*.h*) which contain info about what has been already compiled in the code file they belong to. THis is no automated process, these files need to be written manually. If you have a library (such as the standard lib), it comes with one or more header files which describe the names and parameters of the functions in the code/library they belong to. (Not necessarily all, there might be more in the lib that is used internally only).

    These header files can also describe variables or data structures for global use. And here is the processor specific link. There should be a bunch of header files for the MSP where the hardware regiosters of the MSP are defined as global variables. And the values to write there are defined as global usable values (aliases/macros). These header files are included into your current C file by teh #include directive

    #include "msp430xW42x.h"

    This file may contain all you need or include others depending on your processor, as some things are common across different MSPs, others are device-specific. Look into it and you'll find many definitions which are to be used later in your code. But keep in mind that this is primarily informaiton for the compiler, so it is valid C code, but maybe not too descriptive for humans. It just tells the compiler facts about what is there, not what it is to be used for. But there may be some additional descriptive comments.

    If the TI techdocs talk about a register such as UCA0CTL0 (Usci a0 control register 0), then most certainly a global variable of this name has been defined in one of these MSP header files. So the instruction

    UCA0CTL0 = 1;

    will write the value 1 into the control register. Instead of '1' there usually are aliases available for all the bits you can find in this register.

    I don't have the docs of your processor, but if e.g. there is a register in the docs named LCDM0, then the command LCDM0=0xff; will set all LCD segments this register belongs to to 'on'. As far as I can remember, this would be LCD segment 0 and 1 (lower and upper 4 bit of 0xff) for multiplex0-3 (bit0..3 or 4..7 respectively.) LCDM0=0x82 would set segment 1 on for multiplex stage 1 and segment 0 on for multiplex stage 2 only.

    You can then go and write a C function that takes a value (0..9) and a position (0..15) and maybe a 'dot' flag, and calculates which bits in the LCDMx registers to set or clear so the number appears at the desired position. To make things easier you can define tables with the corresponding segment patterns etc. You can also write a funtion that rotates the current display or shifts it or whatever you want.

    So what does your LCD demo program do? First, it initialized the hardware. This is settign up a timer that will call the interrupt vector in certain intervals. Then the processor ports are set for proper operation (PxSEL selects special hardware funcitonality for the corresponding port pins of thsi port, PxDIR sets the pins for output, default is standard I/O input), then the LCD icontroller is configured and a initial pattern is written into the display .

    Next step don in main() is to set the processor asleep until the timer times out and wakes it up again (this wakeup is done in the basic_timer interrupt fiunction. (the #pragma-lien befor it tells the compiler that this function is to be linked to the timer event). Then Main calls the DisplayAccessories-Function whcih simply writes a new predefined pattern into the LCD memory registers, then port pin P1.0 is toggled (I guess there is an LED attached?) before falling asleep again.

    Try to figure out why the display shows what it shows when the code writes certain value sinto the LCD memory and you should finally understand how it works.

**Attention** This is a public forum