UPC EETAC Bachelor's Degree in Telecommunications Systems and in Network Engineering EEL


P11: Peripheral LCD and libraries of specialised functions


Resources in lectures and labs: L11, Lab11

Example project:

4-bit serial transmitter with LCD display to represent text messages (ASCII code)

1. Specifications

Enhance any of the P10 projects, for instance serial_transmitter, adding a standard LCD display to represent ASCII messages on the two-line 16-character screen. Information can be about the internal state, for example: "Click ST button to start the sequence", "State: Num 0", "Click ST button to stop", etc. Full tutorial recording rec.


Fig 1. The common LCD display LM032L. The LCD controller is the standard Hitachi HD44780 (Dot Matrix Liquid Crystal Display Controller/Driver) or equivalent like the HD44100.



LCD display

Fig 2. This is the typical 4-bit data interface to a microcontroller PORT. It requires up to seven pins for handhaking and data. It is possible to use the PORT's 8th bit where the LCD is connected to switch ON and OFF the LCD power supply. PICDEM2 plus board used PORTD to interface the LCD.

This is a list of three example projects where to apply an LCD to enhance basic circuits:

Project 1 phase #2: Adder_BCD_1digit with an LCD display (from P9).

Project 2 phase #2: 4-bit serial transmitter with an LCD display (from P10).

Project 3 phase #2: 6-bit Johnson sequencer with an LCD display (from P10).

In this page you will find specifications/planning/developing and testing of project 2 phase #2. Its new symbol is drawn in Fig. 2 below. Links for solving project 1 and 3 are placed in learning materials.


Fig 2. Adding an external LCD peripheral in the basic 4-bit serial transmitter from P10. It implies adding new connections to the chip, for instance PORTD pins, and new functions in he source file from an external library, therefore, compiling a multiple-file project (equivalent to plan C2 in previous hardware projects).


Other similar projects:  Several example projects that include an LCD. Study and run them in Proteus to see how the system works and can be programmed taking advantage of all your previous knowledge. Again in some way, the idea of plan C2: some components (C functions this time) in the same top project, therefore a multiple file project.

- Project 1 phase #2: This is the project of Adder_BCD_1digit from P9 enhanced with the LCD to show results. Ideas and discussion, Proteus hardware circuit Adder_BCD_1digit_LCD.pdsprj, C source code Adder_BCD_1digit_LCD.c. This is a picture with some results.

NOTE: This is yet another version of the project where dynamic data is ajusted to 2 bytes (plus the end of string code  '\0' null terminator). It shows how to represent dynamic numerical data, in this case an int result  (Var_Decimal) from an arithmetic operation to a char string (Var_Decimal_ASCII[16] or Var_Decimal_ASCII[3]) sized for LCD. Similar formatting (sprintf()) is required for representing double int or float variable types.

- Project 2 phase #2. This is the project described and discussed in this page.    

- Project 3 phase #2: This is the Johnson_sequencer_mod12 phase #1 from P10 tutorial enhanced with an LCD to represent ASCII messages: Hardware: Johnson_sequencer_mod12_LCD.pdsprj, software:  Johnson_sequencer_mod12_LCD.c. This is the hardware-software diagram highlighting small modifications in output_logic(), LCD library functions, and the circuit running.


2. Planning

1) Copy and rename conveniently a project from P10. For instance, Serial_Transmitter becomes now the project:


 In Fig. 4 is an example list of source files when using the libraries to interfece specific hardware.


Fig. 4. Example of a typical project that includes LCD libraries to drive specific and advanced hardware subsystems (peripherals), thus, becoming a multiple-file project.

2) Organise the hardware. Draw your circuit in a sheet of paper and discuss where to connect: reset (CD), CLK oscillator, digital I/O and push-buttons. A good idea is to connect inputs and outputs in the free pins of a development board like the PICDEM2 Plus, in case you would like to prototype the application. In this board, the LCD display is connected to the microcontroller's PORTD.

3) Determine the functions in the main program that have to be modified in order to control the LCD display. Define the RAM internal variables that will facilitate the communication to the LCD. Use a convenient indicator like var_LCD_flag to prevent writing continuously to the display; this flag is set only when new information has to be shown.  For example Fig. 5 shows the new output LCD message.

output logic

Fig 5. In addition to serial_transmitter circuit outputs in P10 represented in this truth table, a new variable is necessary and the flowchart must solve the idea of writting the CD only when new information.

This new output may be represented in the hardware-software diagram.

4) Plan a sequence for building and debugging the application: the idea is "plan & develop & test" step by step enhancing the initial state diagram with a new feature at a time. For instance:

(1) Start running the copy of P10 project and try to print only the typical ASCII message "Hello World" on the LCD. How long does it take to write a message at the LCD? How can you measure such time?

(2) Add now the messages you like in each FSM state or add new states when necessary.

Fig 5 below is a possible state diagram modified from P10 to allow printing ASCII messages beginning and ending transmissions.

State diagram

Fig 5. State diagram to print ASCII messages on the LCD.

3. Development and 4. Testing (interactively)

1) Draw the schematic of the application in Proteus copying the P10 and modifying it accordingly to your new sketch in paper that includes the LCD connections. so that the LCD is made visible on the top schematic. This is an example circuit Serial_transmitter_LCD.pdsprj

2) Translate to C language your new flowcharts. Run the microcontroller's IDE to develop and compile the C code copying and adapting the previous P10 code. Do it section by section according to your plan, testing whether it works before adding new code. This is an example C code: Serial_transmitter_LCD.c. Remember to include LCD libraries in the project (two header files and two C files).

3) Run the Proteus simulator. Do it in step by step mode while watching variables and placing break points, specially to follow the interrupt flags. This is the zipped project.


Fig. 6.  Circuit running and showing ASCII messages in the LCD display.

4) Learn about the One-shot (single) trigger operation mode of the oscilloscope and how the frame of bit is transmitted once the ST button is detected. Can you add a pulse generator to automatise ST pulses (20 ms duration, 1 Hz) ?

5. Report

This is a page with some guidelines on project oral presentations and written reports. 


6. Prototyping

You're invited to download the application to a given training board an verify that it works as expected and the same as in the simulator.


Other similar projects on sequential circuits

Further discussion and enhancements to this basic circuit:

- How to generate several transmission frequencies?

- How to transmit 8-bit of data?

- How to add a parity bit, for instance an "odd" parity bit?


And finally a couple of good questions:

- How to design a serial receiver?

- How the embedded USART peripheral works, so that the uC can be liberated of such time-consumming tasks?


You can even imagine different coomunication channel scenarios:

- How to adapt 0V and 5 V to the standard RS232 ?

- How to invent a MODEM (1.2 kHz / 2.4 kHz) to be able to use telephone copper lines?

- How to invent a fiber optic adapter (for instance to inplement a kind of HI-FI audio TOSH-LINK) or an infra-red (IR) link for a remote control?

- How to invent a radio link?

Similar examples for other μC:

- These are Internet references (1) (2) (3) with different sets of high-level C functions to interface the LCD display. This example  (PIC16F877A, XC8) is copied  from (1). Thus, you can integrate these libraries into your project and use the LCD functions.

- This is an example (PIC16F877A, XC8) that you can study and learn about what is necessary to use the LCD. The functions were integrated in the old HI-TECH C compiler which is no longer in use. 

- This is an example using ATmega8535 from the former Unit 4.11. And here is the same example slightly modified to be able to write in both rows of the LCD display.

Note on peripheral libraries. To solve this kind of projects involving specialised and complex peripherals you have to rely on external libraries, and there are a variety of them for the same purpose, depending as well on the C compiler. For instance, when installing the PLIBS (periperal libraries) for the XC8 compiler you can access to a variety of libraries including enhanced LCD functions (XLCD). Try this example circuit where all the required functions and header files from PLIBs are copied in the project folder allowing you to compile and run.