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

P10

P11: Peripheral LCD and libraries of specialised functions.

P12


Resources in lectures and labs: L11, Lab11 Project objectives

Highlighted project: 4-bit serial transmitter with LCD display (phase #2)

1. Specifications

Serial_transmitter_LCD. P10 phase#2: enhance 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.

LCD

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.

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.

Represented in Fig.3 there is the new symbol of serial_transmitter.

symbol

Fig 3. 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 hierarchical multiple-file project (equivalent to plan C2 in previous hardware projects).

 


 Other similar projects: on adding an LCD display to a previous design. 

- Adder_BCD_1digit_LCD (phase#2). Project 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 same 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.

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

 

2. Planning

Hardware. As in P10, draw your circuit in a sheet of paper and discuss where to connect: reset (CD_L or MCLR_L), OSC oscillator, digital I/O and push-buttons. A good idea is to connect inputs and outputs in free pins of PICDEM2 Plus prototyping board. In such board LCD display is connected to microcontroller's PORTD. 

LCD wiring

Fig. 4. Wiring 7 wires for interface and another one (RD7) for switching ON/OFF power supply.

Software: Determine the functions in the main program that have to be modified in order to control the LCD display. Define RAM internal variables to facilitate LCD communication. 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 hardware-software diagram. Output_logic() generates the variables to interface with LCD high-level functions.

Diagram

Fig. 5. Hardware-software diagram.

And Fig.6 represents the truth table and its flowchart.

output logic

Fig 6. 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.

 Copy and rename conveniently Serial_Transmitter from P10 that now becomes now the project:

L:\CSD\P11\Serial_Transmitter_LCD\(files)

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

Files

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

 

 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 8 below is a possible state diagram modified from P10 to allow printing ASCII messages beginning and ending transmissions.

State diagram

Fig 8. 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.

new project

Fig. 9. New project name and location. 

Add to the new project five files: three C sources and two headers. Edit XC8 global options.

options

Fig 10. Edit project settings and add the 5 files to the same project.

Edit header file delay.h to ajust crystal OSC frequency.

OSC frequency

Fig 11. Edit delay to ajust OSC frequency.

This is an example C code: Serial_transmitter_LCD.c Remmeber to unzip LCD libraries in the project folder (two header files and two C files).

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

Circuit

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

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

 

6. Prototyping

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

 

Questions and further discussion 

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?


Projects targeted to other microcontrollers  

Similar examples for other μC:

- 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. 


Note on peripheral libraries. To solve 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.