|
|||
|
1-digit BCD counter with LCD (LAB10 design phase #2) |
|
|
|
FSM + interrupts + plan X + LCD
1. Specifications | Planning | Dev. & test | Prototype | report |
Invent a Counter_BCD_1digit_LCD with the same LAB10 (design phase #1) features adding an LCD to show static ASCII messages (design step #1) and dynamic numeric data (design step #2).
![]() |
Fig 1. Symbol of the device to be designed. |
Specifications | 2. Planning | Dev. & test | Prototype | report |
All planning is inherited from design phase #1 and no need to report it again. Let us focus simply on what changes and adaptation will imply the LCD.
If we consider PICDEM2+ board wiring, the simplest way to interface an LCD is to use PORTD, as represented in Fig. 1. The interface will be managed by high-level library functions.
![]() |
Fig. 2. Connecting 7 wires for the LCD interface and another one (RD7) for switching ON/OFF its power supply. |
In this way, we will reassign Q(3..0) and TC10 to other free port pins, as shown in Fig. 3.
![]() |
Fig 3. Q(3..0) are pinned at PORTC(7..4) and TC10 at pin PORTB2. |
For this design step #1 where only static messages will be represented on the LCD screen, no new RAM variables are required.
![]() |
Fig. 3. Hardware-software diagram highlighting small modifications in output_logic() for connecting the LCD. |
The state diagram is the same as it was in design phase #1.
![]() |
Fig. 4 State diagram indicating the ASCII messages in each state. |
output_logic() generates an static ASCII message in each state.
state_logic() is the same, only clearing the LCD flag once used.
init_system() includes LCD initialisation.
read_inputs() to capture CE signal the same.
write_outputs() is the same because writing to the LCD is carried out by the LCD library routines.
ISR() to handle CLK edge detections is the same.
Organise a MPLABX - XC8 IDE project targeting a PIC18F4520 at location:
C:\CSD\P11\counter_BCD_1digit_LCD\(files)
Specifications | Planning | 3. Dev. & 4. test | Prototype | report |
Example circuit: counter_BCD_1digit_LCD.pdsprj.
This is the proposed source code counter_BCD_1digit_LCD.c to be compiled with the LCD library functions.
Run the Proteus simulator. Do it in step by step mode while watching variables and placing break points, specially for following interrupt flags.
![]() |
Fig. 5. The circuit in "run" mode while monitoring the variables in the "watch" window. |
Pay attention on how visualising how the Var_LCD_flag works.
Measure how long does it take to write a message on the screen.
We print a new message for state, thus deduce the maximum frequency of operation of this counter.
Specifications | Planning | Dev. & Test | 5. Prototype | Report |
The idea is to download the application to a given training board to verify that the real product works as expected and the same as it was simulated.
Example 1: Board PICDEM2 PLUS. Target microcontroller: PIC18F4520. Tools: MPLAB X + XC8 + Proteus
This is the production file Counter_BCD_1digit_LCD_prj.X.production.hex that can be programmed directly using the IPE tool. We can use the prototyping area for soldering push-buttons, switches and LED.
![]() |
Fig. 6. Prototype built on a PICDEM2 board. |
Example 3 optional, beyond the CSD learning objectives. Board Explorer 8. Target microcontroller: PIC18F46K22. Tools: MPLAB X + XC8 + MCC + Proteus.
This is the implementation of the design phase #2: adding the LCD display to represent ASCII text. Explorer 8 LCD display is installed through an MCP23S17 16-Bit I/O expander with serial SPI Interface.
C:\CSD\P11\Counter_BCD_1digit_LCD\EXP8_PIC18F46K22\(files)
![]() |
Fig. 7. LCD running in Proteus simulations before downloading the executable to the Explorer 8 board. |
This is the adapted project counter_BCD_1digit_LCD.pdsprj and counter_BCD_1digit_X_LCD.zip.
![]() ![]() |
Fig. 8. Prototype built on Explorer 8 board using the on board LCD. |
This is a project that can be used as a seed example for copying and adapting any other design. Peripherals are developed using the specialised software Microchip Code Configurator (MCC) representing a huge advantage.
Specifications | Planning | Dev. & Test | Prototype | 6. Report |
Follow this rubric for writing reports.