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 Planning Dev. & test Prototype Report

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 LM016L. 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 handshaking 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 design tutorials and assignments.

 


Specifications 2. Planning Dev. & test Prototype  report

A) 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. Connecting RD(6..0) pins to interface the LCD. Another pis RD7 can be used for switching ON/OFF its power supply.

 


B) Planning 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 writing the CD only when new information.

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? Why a var_LCD_flag is required?

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

(3) Add numerical information on the display, mixing text and dynamic data, for instance in this example a count of the messages transmitted. 

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

State diagram

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

 


Specifications Planning 3. Dev. & 4. test Prototype Report

A) Developing hardware

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. Fig. 8 shows an example circuit Serial_transmitter_LCD.pdsprj.

HArdware capture in Proteus

Fig. 8. Captured circuit in Proteus. Here we have two options for triggering transmissions: a manual ST button or an periodic train of pulses.

 


B) Developing software

Translate to C language your new flowcharts. Run the microcontroller's IDE MPLABX 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. The entity Serial_Transmitter becomes Serial_Transmitter_LCD.

NOTE: here we have shortened the project folder name, because using the MPLABX tool is easy to reach Windows file names length limit:

C:\CSD\P11\s_trans_LCD\(files)

Windows folder limit

Fig 9. Warning when reaching Windows naming length limits.

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

Project folder and files

Fig. 10. Example of a typical project that includes LCD libraries to drive specific and advanced hardware subsystems (peripherals), thus, becoming a multiple-file project, as a kind of software plan C2 with several components (functions) under the top schematic.

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

 

Folder and project location

Fig. 11. New project name and location.

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

options

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

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

OSC frequency

Fig 13. Edit delay to adjust OSC frequency.

 


C) Step-by-step testing

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. 13.  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) ?

 


Specifications Planning Dev. & Test 5. Prototype Report

 

Example 1: PICDEM 2 PLUS board. target chip: PIC18F4520

 


Example 2: Explorer 8 board + PIC18F4520

 


Example 3: PICDEM2+  board. target chip: PIC16F877A

- This example  is copied  from (1). Thus, you can integrate these libraries into your project and use the LCD functions.

- This obsolete example was planned for HI-TECH C compiler which is no longer in use. 

 


Example 4: Optional, beyond the CSD learning objectives. Training board: Explorer 8 + Intro_lab + MCC + PIC18F46K22 + MPLAB X + XC8 + Proteus

 


Specifications Planning Dev. & Test Prototype 6. Report

Follow this rubric for writing reports.

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?

- How to design a serial receiver? How to build a prototype for both transmitter and receiver modules?

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

You can even imagine different communication channel scenarios:

- How to adapt 0 V 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 implement a kind of HI-FI audio TOSH-LINK) or an infra-red (IR) link for a remote control?

- How to invent a radio link?