Experiment 6 : Digital Display (Liquid Crystal Display) Objectives : 1) To study the typical design of a LCD module 2) To interface the digital display unit through parallel printer port using C# program. Materials and equipment: Microsoft Window with Visual Studio.NET 2008 DB-25 connector (male) Circuit board LCD module Introduction : Generally, there are two types of LCD modules, the graphics LCD module and the character LCD module. In this experiment, a 16 x 2 character LCD module is being used. LCD module is a low-power display device which incorporates a dot-matrix character generator, display controller and driver function into a single device. It features a 5 x 7 pixel or a 5 x 10 pixel character fonts which could be interface directly to either a 4-bit or 8-bit microprocessors. Figure 1 1. Display Data RAM (DDRAM) The LCD module can be configured to using either a single-line or two-line display mode. The LCD module consists of a display data RAM (DDRAM) which stores the characters for the display. The data in the display data RAM will reflect immediately on the LCD screen once the Display mode is ON. April 2010 1 ITE/EC5103PA
The following table describes the DDRAM address and the character position. EXPT6_DD(LCD) Line 1 Position 1 Line 2 Position 14 Line- Position DDRAM Address Line- Position DDRAM Address 1-1 1-2 1-3 1-4 1-5 1-6 1-7 1-8 1-9 1-10 1-11 1-12 1-13 1-14 1-15 1-16 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 2-1 2-1 2-3 2-4 2-5 2-6 2-7 2-8 2-9 2-10 2-11 2-12 2-13 2-14 2-15 2-16 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 2. Cursor Display and Blinking Cursor display and blinking of the character at the cursor position are controlled using the Display ON/OFF instruction. The cursor position is at the character corresponding to the address counter value. 3. Reset and Initialise When Power-ON the LCD, the internal reset circuit will initialize the LCD for a duration of 10ms. Upon completion of self-initialisation, the LCD can be configured using the following initialisation sequences: a. Set Function (D/L = 1, N = 1, F = 0) - (Write Instruction) Sets 8-bit interface size, 2-line display size and 5 x 10 pixel character font b. Set Cursor/Display control (D = 1, C = 1, B = 1) - (Write Instruction) Sets the display, the cursor and character blinking ON c. Set Entry Mode (I/D = 1, SH = 0) - (Write Instruction) Sets address counter auto-increment and sets display shift OFF d. Clear Display - (Write Instruction) The program for the LCD initialization is provided. 4. Display Character The following sequences explain the methods for character to be displayed onto the LCD screen: a. Set the DDRAM address (Position for display ) - (Write Instruction) Specifics the location of the display by setting the address counter b. Write the character to the DDRAM (Write Data) April 2010 2 ITE/EC5103PA
Procedures: 1. Connect the LCD circuit to the PC. 2. Activate the Microsoft Visual Studio program and create a New Project. Choose the Windows Forms Application templates with Visual C# Language. 3. Create the project as LCDBasic, and type the C# program in Program 1. 4. Create a window form as shown in Figure 2. The Test Button is to display test character on the LCD upon click. The Send Button is to display message on the LCD upon click. Figure 2 5. Create a display string function to display a message on the LCD. Hints: Create a function call displaystr() as follow: public static void displaystr() byte[] temp = new byte[33]; for (int i = 0; i < LCDString.??????; i++) temp[i] = (byte)lcdstring[i]; displaychar(temp[i], (byte)i); // Students are required to understand array concept 6. Modify the program to output the following messages on the LCD module in sequence with 1 sec delay in between: WELCOME TO ITE ELECTRONICS * ENGINEERING * Name: XYZ Name: ABC Figure 3 7. Demonstrate the program when working. Staff s signature/date: April 2010 3 ITE/EC5103PA
Program 1 using System; using System... System.Runtime.InteropServices; namespace CPA_LCDBasic public partial class Form1 : Form public Form1() InitializeComponent(); private void Form1_Load(object sender, EventArgs e) LCD.initLCD(); private void button2_click(object sender, EventArgs e) LCD.?????? =????.???? LCD.displayStr(); private void button1_click(object sender, EventArgs e) LCD.displayChar(0x41,??); // Display the Testing Character @ Location 1-2 public class LCD public static string LCDString; public static void writeinstr(byte Instr) PortAccess.Output(0x37A, 0x03); // RSL PortAccess.Output(0x378, Instr); PortAccess.Output(0x37A, 0x02); // EH System.Threading.Thread.Sleep(1); PortAccess.Output(0x37A, 0x03); // EL public static void writedata(byte Data) PortAccess.Output(0x37A, 0x01); // RSH PortAccess.Output(0x378, Data); PortAccess.Output(0x37A, 0x00); // EH System.Threading.Thread.Sleep(1); PortAccess.Output(0x37A, 0x03); // EL public static void initlcd() writeinstr(0x??); // Set LCD Function Set (D/L = 1, N = 1, F = 1) writeinstr(0x??); // Display ON/OFF CTRL (D = 1, C = 1, B = 1) writeinstr(0x??); // Set Entry Mode (I/D = 1, S = 0) writeinstr(0x??); // Clear Display public static void displaychar(byte LCDData, byte loc) byte temp; temp =(byte) (0x80 loc); writeinstr(temp); writedata(lcddata); public class PortAccess. April 2010 4 ITE/EC5103PA
Questions: Refer to Appendix 1 & 2 on LCD datasheet and instruction set, complete the following questions: 1. (i) LCD Module Part Number (ii) Number of character (iii) Character font (v) (vi) Viewing angle Dot Size (vii) LCD Type (TN/STN/DSTN/TFT) (viii) Supply Voltage for logic (Under normal) (max) (min) 2 Write down the instruction type and the data code for the respective LCD function. Function Set DDRAM address in address counter to 4A Set interface data length to 8 bit, using 2 display lines and set the font type to 5X10 dots Set all Display, Blinking and Cursor to ON mode Assign cursor moving direction to move to the right and disable the shift of entire display Write 20H to DDRAM set DDRAM to 00H from AC Instruction Set DDRAM Address Instruction Code (Hex) CA 3F April 2010 5 ITE/EC5103PA
3 State the pin assignment of the LCD module. Pin No. Symbol Function 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 April 2010 6 ITE/EC5103PA
Appendix 1: LCD(16x2) module Datasheet April 2010 7 ITE/EC5103PA
Appendix 2: LCD Instruction Set April 2010 8 ITE/EC5103PA