Hi. My name is Steve and I am a newcomer to HCS/Coldfire microcontrollers. I have some experience with AVR but would like to extend my programming skills and use a DEMOJM board I recently got hold of.
Please could anyone help me with connecting a 16x2 LCD display to the DEMOJM board using the JM60 daughter card??
I mean the pinouts and if there is any code available to help get me started.
Also if you know of any good examples I could successfully use with the DEMOJM and the jm60/ mcf128 cards demonstrating basic digital inputs and outputs/ connecting the pots and using the accelerometer etc ( not including the PEMIcro examples) I would be very very grateful. I also have a Freescale M68EVB912C32 Dev board coming my way so this will be interesting to look at as well. Eventually I would like to use this platform for university projects. ( I am studying Audio Systems at London Metropolitan Uni.)
Thanks,
Steve.
Hello Steve,
You will firstly need to decide on the interface method to use - there are a number of possibilities. This type of LCD display has a parallel data interface, plus two or three control signals. You will need to choose between the following:
These displays usually require 5 volt supply. With a MCU Vdd of 3.3 volts, the interface should still work correctly (for write operations only). But probably better to operate everything from a common 5 volt supply unless there are specific reasons for doing otherwise.
You have not said whether you will be programming in C or assembler.
Regards,
Mac
Hi guys and thanks for the H.U.
The LCD display I have is a 16 pin 16x2. It comes with the Hitachi 44780 driver. I have had it working using an Arduino board and the LCD library.
As for the language. I'm considering learning to program in C as it is closest to what i have used before ( i.e. arduino IDE language.)
Assembler fascinates me though. I remember dabbling with assembler years ago on an Amiga computer... and before then, further back in the mists of time with a ZX81 ( 6 line entry programs and pages and pages of hexadecimal numbers..: s )
But I think C would be more applicable to my area of interest.. ( MIDI and sound control .)
At the moment I have had some sucess with running some simple example programs for the DEMOJM board like a 4 led binary counter, and a blinker..
Hello Steve,
The Hitachi driver is capable of both 8-bit and 4-bit operation. The mode is determined by the initialisation sequence used. I will assume that you will be using 4-bit mode. I have attached some code that you may be able to adapt for your purpose.
Regards,
Mac
Thanks very much BigMac,
Now I just have to work out how it works in C and how I can assign the pins on the MCU port of the DEMOJM board and how to write to it etc.... hmmmm....
I admit being a total total noob extraordinaire,,,,,,,
Hello,
mUbase wrote:Now I just have to work out how it works in C and how I can assign the pins on the MCU port of the DEMOJM board and how to write to it etc.... hmmmm....
The key to these questions is the header file.
// File: LCD.h// Provides 4-bit interface with Hitachi HD44780 device./************************************************************************/#ifndef LCD_MACROS#define LCD_MACROS#include "derivative.h" // For 'byte' typedef// Macros for LCD usage.#define _NEW_COP /* Comment out if old COP timer with single write to SRS register. */#ifndef BUSFREQ /* BUSFREQ may already be defined (main.c). If so, #include this file after the definition. */#define BUSFREQ 4000000 // Default bus frequency in Hz#endif#define LCD_LINE_LEN 24 // Adjust to suit LCD display/************************************************************************//* Hardware connections for LCD (4-bit mode): (Alter to suit actual MCU port usage)PTB0-PTB3 = DB4-DB7 Data busPTB4 = RS Register selectPTB5 = R/W Read / WritePTB6 = E EnablePORTB 0b00000000 |||++++- data bus 0x0F ||+----- RS 0x10 |+------ R/W 0x20 +------- Enable 0x40*/#define LCD_PORT PTBD#define LCD_DDIR PTBDD#define LCD_DDMASK 0x7F // Data direction mask#define LCD_DMASK 0x0F // LCD data uses lower nybble#define LCD_RS PTBD_PTBD4#define LCD_RW PTBD_PTBD5#define LCD_E PTBD_PTBD6/************************************************************************/// LCD control codes:#define DCLR 0x01 // Clear display and home cursor#define HOME1 0x80 // Home cursor to start of line 1#define HOME2 0xC0 // Home cursor to start of line 2#define SHFTOFF 0x06 // Shift off#define SHFTON 0x07 // Shift on#define DOFF 0x08 // Display off#define CURSOFF 0x0C // Display on, cursor off#define CURSON 0x0E // Display on, steady cursor#define CURSBL 0x0F // Display on, blinking cursor#define CURSL 0x10 // Move cursor left#define CURSR 0x14 // Move cursor right#define SHFTL 0x18 // Shift display left#define SHFTR 0x1C // Shift display right#define SINGLE 0x20 // Single line mode & 4-bit I/F#define DUAL 0x28 // Dual line mode & 4-bit I/F// Cursor position macros:#define MOVL1(p) LCD_ctrl((p) + HOME1) // Set addr counter to line 1 position#define MOVL2(p) LCD_ctrl((p) + HOME2) // Set addr counter to line 2 position/************************************************************************/// Function prototypes:void LCD_init( void); // Initialise LCD module (4-bit mode)void LCD_ctrl( byte ch); // Send control byte to LCDvoid LCD_char( byte ch); // Send display character to LCDvoid LCD_str( const byte *sptr); // Send string data to LCDvoid LCD_partstr_L1( const byte *sptr); // Send partial string to L1 of LCDvoid LCD_partstr_L2( const byte *sptr); // Send partial string to L2 of LCD#endif
The hardware connections for the LCD are currently assumed to be via port B. However, another port may be assigned by altering the macros for LCD_PORT, etc. I have assumed that the control signals will occupy the same port as the data nybble. These could easily be assigned to different port(s), provided the data direction setting for these pins is handled elsewhere.
The operation of the Hitachi device is slow, and delays are required throughout the code for correct operation. These are minimum delay requirements - actual delays in excess of the minimum delay do not affect the display operation. Two factors will determine the delay calibration - the MCU bus frequency used, and the COP timer handling method employed within the MCU - so these need to be defined.
An additional thought - perhaps the default bus frequency should be altered to the maximum allowable bus frequency.
#define BUSFREQ 20000000 // 20MHz
Then if the actual bus frequency is not specified within main.c, the delays generated will always exceed the minimum requirement.
From the function prototype list, the first four functions are the usual basic ones. The last two functions may be useful for special applications that require display scrolling. The LCD_LINE_LEN macro is used by the latter functions only. There are also macros available to position the cursor. These are called similarly to a function.
For a definition of what each control code does, you will need to refer to the display datasheet, or the Hitachi datasheet.
Regards,
Mac
Thanks fot the info. I'll look into it at the weekend.
Wow this is a new dimension. My tutor at Uni is supporting me in my uC endeavours. Nice to know that people care. I hope one day I can pass on uC info ...
take care.
STeve.
Hi again BigMac. I have the LCD connected and have started a new codewarrior project. The lcd pins are connected to the MCU port as shown. Using port B.
I have the c anf h files.
Do I set them both up as includes in the main file??
Hello,
If you have not already done so when you created the new project, the two files LCD.c and LCD.h will need to be copied to the 'Sources' folder of the project. These files will then need to be added to the project structure using Project | Add files .. menu item.
Within main.c you will then need to #include the LCD.h header file only. This will allow the various LCD functions to be called from within main.c. You will also need to update LCD.h with the default BUSFREQ value that you are actually using for your experiments.
Regards,
Mac
hi Steve
google the LCD controller IC's datasheet. They usually have a good flow chart of the initilisation proceedure.
There are many code examples on the net. I can give you assembler code.
Some tips:
- Don't forget the delays after each command.
- The view angle pin usually needs only a resistor to ground (typ. 1K)
- If you don't need to read from the device, then the R/W pin can be tied low.
don