Module 5 : Experiments on Microcontrollers

Lecture 43 : Interfacing PIC16F877 Microcontroller with an LCD

Aim

To interface LCD (Displaytech 162A) with PIC16F877microcontroller and to display "IITK" in the Liquid Crystal Display (LCD).

Components/Softwares

  1. MPLAB IDE (PIC microcontrollers simulator)
  2. PIC BURNER 3 with software to load the code
  3. LCD (Displaytech 162A)
  4. Computer System with Windows operating system and RS 232 cable
  5. PIC16F877 Microcontroller
  6. +5V D.C Power Supply
  7. Resistors - 10K Ω-1,50Ω-1
  8. Capacitors - 27 µ F-2
  9. Potentiometers - 10K Ω -1
  10. 20MHz Crystal oscillator
  11. SPST switches -1

Fig 43.1 A view of the PIC programmer connected to the PC serial Port (COM1)

Procedure

  1. Write the assembly code in MPLAB IDE simulator , compile it and check for errors
  2. Once the code was error free, run it and check the output in the simulator.
  3. After checking the code in the simulator, load the code (in .HEX format) into PIC16F877 microcontroller using PIC BURNER3.
  4. Make connections as shown in the circuit diagram.
  5. Switch on the power supply and observe "IITK" displayed in the LCD.
Conclusion

LCD was successfully interfaced with PIC16F877 microcontroller and displayed "IITK" in the LCD.

Assembly Code

Circuit Diagram
Fig 43.2 Circuit Diagram
Fig 43.3 Circuit assembly on breadboard
Liquid Crystal Display (LCD-Displaytech 162A )

LCD Displaytech 162A consists of a LCD panel, a controller IC (KS0070B) and a back light LED. The LCD module consists of total 16 pins in which, 2 are for power supply, 2 pins for Backlight LED, one pin for contrast adjustment, 3 pins are for control signals and 8 pins are data pins. In order to display any data, we need to do certain initiations. The following are the main three steps in displaying any data in the LCD display.

  1. Initializing LCD by sequence of instructions
  2. Executing commands depending on our settings in the LCD
  3. Writing data into the DRAM locations of LCD in the Standard Character Pattern of LCD

For doing above steps, refer the manual for LCD and follow the instructions and timing diagrams strictly.

MPLABIDE

MPLABIDE is a free software which can be downloaded from the website www.microchip.com

Working with MPLABIDE :

MPLABIDE is a simulator for PIC microcontrollers to write and edit the code in assembly language, compile it and also to run the code. Output can be verified using simulator.

Steps to Use MPLABIDE
  • After Installing the software MPLABIDEv7.2,open MPLABIDE.
  • To built a new project, open
    Project Project Wizard
    Project wizard New
    Device 16F877
    Location (Ex:C:\ProgramFiles\Microchip\MPASM Suite\MPASMWIN.EXE) Next
    <Project name>&<Project Directory> Next
    (Add file "f877tmpo.asm" which was located in programfiles microchip MPASMSuite Template Object)
    (Add file "16f877.lkr" which was located in programfiles microchip MPASMSuite LKR)
    Next Finish
    To have more clear refer to MPLABIDE help files.
  • After building the project open the editor f877tmpo.asm and write the assembly code
  • After writing the assembly code in the editor, build the project by clicking on the following option
    Project Build all
  • Check for the errors in the output window
    View Output
  • Once the error free code was made, simulate the code by following option
    Debugger Select Tool MPLAB SIM
  • Simulator options are
    1. Step into - Each time only one instruction will be executed (Single stepping mode)
    2. Run - To run the whole code at once.
    3. Animate - to animate the executing the code
  • Additional things:
    1. To view DRAM, program memory, SFRs, and External memory use the option VIEW
    2. To set break points in the code (where simulation stops at that point). Debugger Breakpoints
  • To stop the simulation
    Debugger Halt
After checking the code in the simulator, the code (file with .HEX extension) is loaded into 16F877 microcontroller using PIC BURNER 3.
PIC BURNER3

PIC BURNER3 can be used to program PIC microcontrollers. The steps to be followed to program the IC safely are as follows.

  1. Connect the PIC BURNER3 through RS232 Port to computer system with windows98 as operating system.
  2. Execute the file "icprog" which was in the software that comes with PIC BURNER3.
  3. Set the device as PIC16F877
  4. Switch on the power supply of PIC BURNER3
  5. Settings Hardware { JDM Programmer,Com1,Direct I/O}
  6. Settings Hardware check 1. on clicking "Enable Data out", Data in must be clicked automatically
    2. on clicking Enable MCLR, red LED on the PICBURNER3 must glow
  7. Settings Options Confirmation [ Erasing the devise,Code Protecting the Devise]
  8. Settings Options MISC Process Priority Normal
  9. Settings Options Programming Verify After Programming.
  10. Remaining options keep them at default settings. [Refer Manual of PICBURNER3 for detail]
  11. Now insert the 16F877 microcontroller into the slot provided on the PICBURNER3 as the direction specified in the manual of PICBURNER3.
  12. load the .hex file
    File open file
  13. Command Erase All
  14. Command Blank Check
    Then there should be a notice on the window that "Device is Blank "
  15. Command Program All
  16. Command Blank Check
    Then there should be a notice on the window that "Device is not blank at address 0x0000H".
  17. Close the window, remove the IC from the PIC BURNER3 and switch off the power supply for PIC BURNER3.