AK47m Project Part 6 (Adding a LCD display to the system)

I have added a LCD two line display to my project. I obtained a two line by 16 characters wide that costs about £6. LCD displays generally have a standard interface based on the Hitachi model. It is easily hooked up to a 16F628 PIC. There are 4 data lines, 2 control lines and 5v power lines. Only 4 of the 8 data lines are used and the LCD is programmed using 4 bit nibbles of data. The LCD display that I obtained has the pin out arranged as two lines of solder connections. The usual ones have a single line. The solder pad with a square surround is pin 1 and the pins are numbered from left to right so the odd numbered pins are on the left and the even numbered pins are on the right.

Note that the LCD is powered from the 5v supply but the control and data lines are driven to +3.5v from the PIC. The 5v supply is taken from the USB connection to the power supply. The 3.5v supply for the PIC is derived from the Raspberry PI.

The excellent MikroElectronika pascal compiler has a library to drive the LCD and a simple means to configure the PIC IO pins used to connect to the display. The LCD display connections to the PIC are as follows:-

Pin1 - Ground

Pin2 - +5v

Pin3 - contrast (grounded)

Pin4 - RS (PIC A1)

Pin5 - RW (grounded)

Pin6 - En (PIC A0)

Pin7-10 - High Data (grounded)

Pin11-14 - Low Data (PIC B4-B7)

Pin15 -Backlight LED (+5v)

Pin16 -Backlight LED (grounded)

 

The PASCAL program requires a declaration of the pin out as follows:

var LCD_RS : sbit at RA1_bit;
var LCD_EN : sbit at RA0_bit;
var LCD_D4 : sbit at RB4_bit;
var LCD_D5 : sbit at RB5_bit;
var LCD_D6 : sbit at RB6_bit;
var LCD_D7 : sbit at RB7_bit;

var LCD_RS_Direction : sbit at TRISA1_bit;
var LCD_EN_Direction : sbit at TRISA0_bit;
var LCD_D4_Direction : sbit at TRISB4_bit;
var LCD_D5_Direction : sbit at TRISB5_bit;
var LCD_D6_Direction : sbit at TRISB6_bit;
var LCD_D7_Direction : sbit at TRISB7_bit;

The display is initialised using the following code, note that the compiler automatically links in the LCD driver library.

 Lcd_Init(); // Initialize LCD
 Lcd_Cmd(_LCD_CLEAR); // Clear display
 Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

The display is updated as the following example:

 txt := 'PHSC (c)2018';
 LCD_Out(1,1,txt); // Write text in first row from character pos 1
 txt := 'AK47M Vs 1.0';
 LCD_Out(2,1,txt); // Write text in second row from character pos 1

When I first ran my program, nothing happened ! Eventually I realised that the contrast was not connected on Pin3. This is normally driven by a voltage divider to adjust the voltage. I simply grounded the pin and it worked fine.

These photos show the individual components:-

This is the LCD display with wires soldered on that connect to the PIC.

 

This is the display PIC. The wires to the right go to the LCD display. The wires to the left take power to the configuration PI card and receive MIDI data.

 

This is the connector to a PI B+ card to obtain power and send MIDI data to the PI. There are four connections : +5v, +3.5v, Ground, UART Receive.

 

Here are the three components connected up.

 

The PIC uses its internal UART to monitor the MIDI messages. I have defined a set of MIDI messages for internal use. These are kept short as there is no flow control. This means I can use a one wire connection to operate the LCD display.

Internal MIDI messages have the general format:

$F1 <length of data> <function> <data>

except for key press messages that have the format

$F1 $00 <key press>

Here is a summary of the messages :-

Key press - $F1 $00 <key press>
Display 1 - $F1 <length> $01 <text up to 16 chars>

Display 2 - $F1 <length> $02 <text up to 16 chars>

Select Style File - $F1 <length> $03 <style file name with extension>

Style Params - $F1 $18 $04 [Voice PC]x8 [Voice Vol]x8 [Voice Enable]x8

Style Aux - $F1 $04 $05 <tempoH> <tempoL> <transpose> <variation select>

Part Params - $F1 $10 $06 [Part PC]x4 [Part Vol]x4 [Part Flags]x4 <Split point> <Split Enable> <spare> <spare>

Chord Finder - $F1 $02 $07 <chord pitch> <chord type>

 

Leave a Reply