[go: up one dir, main page]

100% found this document useful (2 votes)
232 views44 pages

Digital Systems III Practical Manual - Ver1.2

This document provides instructions for using MPLAB X IDE to create and run PIC microcontroller projects. It describes how to create a new project, select the device and compiler, add source files, troubleshoot errors, and run a simulation. The objectives are to create MPLAB projects, troubleshoot code errors, and debug simulations. Practical experiments will cover programming PICs using MPLAB and interfacing with components like LEDs, switches, displays and more.

Uploaded by

sifisodlungwana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
232 views44 pages

Digital Systems III Practical Manual - Ver1.2

This document provides instructions for using MPLAB X IDE to create and run PIC microcontroller projects. It describes how to create a new project, select the device and compiler, add source files, troubleshoot errors, and run a simulation. The objectives are to create MPLAB projects, troubleshoot code errors, and debug simulations. Practical experiments will cover programming PICs using MPLAB and interfacing with components like LEDs, switches, displays and more.

Uploaded by

sifisodlungwana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Practical Manual Ver.1.

By
Mr. W.M. Ndlovu & Mr. N. Mngomezulu
Digital Systems III PRACTICAL MANUAL
Copyright © WM.Ndlovu, N.Mngomezulu. All rights reserved

 The student is encouraged to read the text book and additional text given in the study
guide for more details in the topics covered in this document.

PLEASE NOTE:
 It is compulsory that all codes are to be typed on a computer program called
‘Notepad’ or ‘Notepad++’ and must be saved on USB memory stick before
attending any lab session!!
 It is compulsory that a student brings his/her own power supply when attending any
lab session!!

In The Lab:
 The student will be introduced to how the PIC Microcontroller work, how are they
interfaced with peripheral components and programming using C18 and MPASM
compilers.
 Practical experiments will be covered in the lab and a student MUST attend one lab
session per week.

Lab Objectives:

 The student must be able to apply embedded C language and Assembly language
programming on the practicals.
 The student must be able to create, edit and build projects using MPLAB X IDE.
 The student must be able to use C18 & MPASM Compilers to instruct a PIC
Microcontroller to perform a certain task.
 The student must be able to build and simulate the circuit on Proteus simulation software.
 The student must be able to interpret datasheets and components applications.
 The student must be able to do a hands-on type of work, building circuits using PICkit 3
Programmer & real components.
 The student must be able to understand the application of the practical & components.

Digital Systems III, Practical Manual 1


Contents:
1. LAB 1- MPLAB X IDE-----------------------------------------------------------------pg3
 Creating a project on MPLAB X IDE.
 Code troubleshooting and simulation on MPLAB X IDE.
2. LAB 2- Proteus 8------------------------------------------------------------------------pg10
 Creating a project on Proteus 8.
3. LAB 3- Hardware and Tools ---------------------------------------------------------pg14
 PICkit 3 Connection on breadboard.
 PICkit 3 Setup on MPLAB X.
 Programming a microcontroller.
4. Experiment 1 ----------------------------------------------------------------------------pg17
 Turn ON 1 LED.
 Turn ON 8 LEDs.
 Delay Loop, Subroutines & LED Flashing.
5. Experiment 2 ----------------------------------------------------------------------------pg23
 Read a Switch.
 Read Multiple Switches.
6. Experiment 3 ----------------------------------------------------------------------------pg28
 LESSON 6: The 7-Segment display Interface.
7. Experiment 4 ----------------------------------------------------------------------------pg31
 LESSON 7: Keypad Interface
8. Experiment 5 ----------------------------------------------------------------------------pg36
 LESSON 8: LCD Interface

APPENDIX A: PIC18F458 Pin Layout and Peripheral Features. -------------------------pg40


APPENDIX B: PICkit 3 Pin Layout. ----------------------------------------------------------pg43

Digital Systems III, Practical Manual 2


LAB 1 MPLAB X IDE
Learning Objectives:
After completing the chapter, you must be able:
 To know how to create source files and a project using MPLAB X.
 To troubleshoot and correct errors when compiling a source code.
 To debug and run a simulation of a source code using MPLAB X.

1.1. Creating A Project On MPLAB X IDE


1.1.1. Create a folder on desktop.
Create your working folder on the desktop for easy access. Right click – New –
Folder. Rename the folder with a name of your choice.

1.1.2. Open MPLAB X IDE.


Open MPLAB X on start menu or locate MPLAB X IDE icon on desktop.

Double click on the icon.

1. Window Menu.
Click on Window –
Projects, to view existing
projects.

2. Project window. 3. Output window.


This section shows This section shows the
existing projects. It is details on the errors or give
recommended that you a status of the code when
close all existing projects. building the source code
Point at the project and
Right click - close

ATTENTION: It is recommended that you close all project in “Project Window”!!!!


On the menu bar Click – File – Close All Projects.

Digital Systems III, Practical Manual 3


1.1.3. Create New Project.
After MPLAB X is opened, click on the menu bar - File - Create a new project

1.1.4. Choose Project type.


Choose “Microchip Embedded” and “Standalone Project”. Click Next.

1.1.5. Select Device.


Family: Click on the drop down list and select “Advanced 8-bit MCUs (PIC18)”.
Device: Click on the drop down list, scroll down and select “PIC18F458”. Click
Next.

1.1.6. Select Tool.


Click on the Programmer that you connected on your computer. If the project is a
simulation based project, select “Simulator”. Click Next.

Digital Systems III, Practical Manual 4


1.1.7. Select Compiler.
Click on the compiler you intend to use. In our case select “C18 (v3.47)” for C
language or “mpasm (v5.71)” for Assembly language. Click Next.

1.1.8. Select Project Name and Folder.


Project Name: type the project name WITHOUT SPACES.
Project Location: Click – Browse to locate your project folder.

Click – Desktop (on the left hand icons), select the folder you created earlier.

Click – Open and Click Finish.


Digital Systems III, Practical Manual 5
Your Project will now appear on “Project Window”. Click on + to view subfolders.

1.1.9. Source File.


Right Click on “Source Files” folder. Click - New – C Source File… for C language
or Click - New – pic_8b_general.asm….for Assembly language.

File Name: type the same project name WITHOUT SPACES. Make sure that the
“Extension” is C for C language is selected. Click – Finish.

Digital Systems III, Practical Manual 6


1.2. Code Troubleshooting and Simulation On MPLAB X IDE
1.2.1 Type the Code below on your Source File.

Digital Systems III, Practical Manual 7


1.2.2. Compile or Build a code.
Click on “Clean and Build” icon to compile your source code.

1. Clean and Build.


This compiles and build a
source code and
generates a “.hex” file in
a project folder.

A “BUILD SUCCESSFUL” message will appear in the “Output Window”.

If not successful then proceed to Code Troubleshooting.


1.2.3. Code Troubleshooting on a C Source file.
After clicking on “Clean and Build” icon, the “BUILD FAILED” message and
error messages will appear in the “Output Window”. 2.Error location.
Error is on “line 11” of the
“example01.c” source file.

3.Error type.
The error is caused by an
instruction typed wrong.

Locate an underlined blue sentence with the word “Error” and Click on it.

4.Error identification.
The cursor blinks on “line 11” of the “example01.c” file. Error is
caused by line 9, “TRISC=0x0F” line without “;” at the end.

Digital Systems III, Practical Manual 8


1.2.4. Code Troubleshooting on an Assembly Source file.
After clicking on “Clean and Build” icon, the “BUILD FAILED” message and
error messages will appear in the “Output Window”.

2.Error location.
Error is on “line 22” of the
“assembly011.asm” source file.

3.Error type.
The error is caused by an
instruction typed wrong.

Locate an underlined blue sentence with the word “Error” and Click on it.

4.Error identification.
The cursor blinks on “line 22” of the “assembly011.asm” file.
Error is caused by “TRIC” which is supposed to be TRISC.

After correcting all the errors, click on “Clean and Build” icon again.

1.2.5. Simulation using MPLABX.


Click on “Debug” icon or on the menu bar – Debug – Debug Main Project.
Stop and Pause icons will appear.

5.Debug.
Click Pause icon. This compiles, build a source code
and simulate the project on MPLAB X.

Click on the menu bar – Window – Debugging – Watches or Variables.

Digital Systems III, Practical Manual 9


On the “Output Window”, Right Click on “Enter new watch” click New Watch.
Select TRISB and Click OK.

Repeat above steps for TRISC, PORTB and PORTC.

Click “Reset” icon. Click “Step Into” Reset Step Into

Alternatively, press F7 key on the keyboard.


Observe the green bar moving on each instruction line, one step at a time. You will see that
the values on variables are also changing as the bar moves.

Digital Systems III, Practical Manual 10


LAB 2 PROTEUS v8
Learning Objectives:
After completing the chapter, you must be able:
 To design a microcontroller based project on Proteus v8.
 To interface a microcontroller with different components and use them as inputs
or outputs.

2.1. Creating A Project On Proteus v8


2.1.1. Open Proteus 8 Professional.
Open Proteus 8 Professional on start menu or locate the icon on desktop.
Double click on the icon.

2.1.2. Creating a Project.


On the page “PROTEUS DESIGN SUITE 8.xx” Click File – New Project.

2.1.3. New Project Wizard: Start.


Name: use the same name, Path: click Browse and locate the project folder on
desktop. Click - Next.

Digital Systems III, Practical Manual 11


2.1.4. New Project Wizard: Schematic Design.
Select the size of the schematic or select DEFAULT. Click - Next.

2.1.5. New Project Wizard: PCB Layout.


Select “Do not create a PCB layout”. Click - Next.

2.1.6. New Project Wizard: Firmware.


Click “Create Firmware Project”.
Family: Click on the drop down list and select “PIC18”.
Controller: Click on the drop down list, scroll down and select “PIC18F458”.
Compiler: Click on the drop down list, scroll down and select “MPLAB C18” or
“MPASM”.

For C Language

For Assembly

Digital Systems III, Practical Manual 12


Click Next and Click Finish.
2.1.7. Source Code.
Copy the source code from MPLAB X and paste it in the source code page on
Proteus.

2.1.8. Compile or Build a code.


Click on “Build” icon to compile your source code.

2.1.1. Connect components to the microcontroller.


Connect input & output components, 10kΩ and a crystal accompanied by 22pF
capacitors.
VDD

R1
10k U1
13 15
OSC1/CLKI RC0/T1OSO/T1CKI ?
1 16
MCLR/VPP RC1/T1OSI ?
17
RC2/CCP1 ?
2 18
1

RA0/AN0/CVREF RC3/SCK/SCL ?
3 23
C1 RA1/AN1 RC4/SDI/SDA ?
22pF
X1 4
RA2/AN2/VREF- RC5/SDO
24
?
CRYSTAL 5 25
RA3/AN3/VREF+ RC6/TX/CK ?
FREQ=4MHz 6 26
RA4/T0CKI RC7/RX/DT ?
2

7
RA5/AN4/SS/LVDIN
14 19
RA6/OSC2/CLKO RD0/PSP0/C1IN+
20
C2 RD1/PSP1/C1IN-
33 21
22pF RB0/INT0 RD2/PSP2/C2IN+
34 22
RB1/INT1 RD3/PSP3/C2IN-
35 27
RB2/INT2/CANTX RD4/PSP4/ECCP1/P1A
36 28
RB3/CANRX RD5/PSP5/P1B
37 29
RB4 RD6/PSP6/P1C
38 30
RB5/PGM RD7/PSP7/P1D
39
RB6/PGC
40 8
RB7/PGD RE0/RD/AN5
9
RE1/WR/C1OUT/AN6
10
RE2/CS/C2OUT/AN7
R9 R8 R7 R6 R5 R4 R3 R2 PIC18F458
330 330 330 330 330 330 330 330 CLOCK=4MHz

D8 D7 D6 D5 D4 D3 D2 D1

After connecting the circuit, RUN the simulation. Observe the operation of the circuit.
Digital Systems III, Practical Manual 13
LAB 3 HARDWARE & TOOLS
Learning Objectives:
After completing the chapter, you must be able:
 To know how to connect and use PICkit 3 programmer.
 To build and transfer a “hex” file generated from MPLAB X into the actual I.C.
 To connect and test the project on the breadboard.
 To correctly connect the microcontroller pins on a breadboard.

EQUIPMENT
Tools Components
5V Power supply 1 x PIC18F458 microcontroller
1 x Side Cutter 1 x 4MHz Crystal
1 x Pliers 2 x 22pF Capacitors
5 x Male to Male Jumper wires or 1 x 10kΩ Resistor
Breadboard wires 8 x LEDs
Breadboard 8 x 220-470Ω Resistors
Digital Multimeter
PICkit 3 Programmer/Debugger
PIC18F458 Datasheet
USB MEMORY STICK!!

3.1. PICkit 3 Connection On Breadboard


3.1.1. Connect all components and required pins on the breadboard.
Refer to the microcontroller’s datasheet and APPENDIX A on this practical manual.

3.1.2. Connect a +5V power supply to the circuit on breadboard.


Refer to the microcontroller’s datasheet and APPENDIX A on this practical manual.

3.1.3. Connect pins 1 to pin 5 of a PICkit 3 programmer.


Identify MCLR, VDD, VSS (Gnd), PGD and PGC pins on the microcontroller. Refer to the
microcontroller’s datasheet and APPENDIX A on this practical manual.
Match and connect microcontroller pins with PICkit 3 programmer pins. Refer to
APPENDIX B on this practical manual.
Note that we do not connect LVP pin of the programmer.

Digital Systems III, Practical Manual 14


3.2. PICkit 3 Programmer Setup On MPLAB X
3.2.1. Connect PICkit 3 with a computer to be used via USB port.
The programmer driver’s will be installed automatically.

3.2.2. Linking the programmer with the project.


Click- File – Project Properties (with project name).

Click on the serial number of the PICkit3 you are using. This is to change MPLAB X from
using Simulator to use the PICkit3 programmer. Click – Apply – OK.

Digital Systems III, Practical Manual 15


3.3. Programming A Microcontroller
3.3.1. Programming the device.
Click on the “Make and Program Device Main Project” icon (the one with down arrow).

Click OK on the dialog box. It’s a caution.

“Programming/Verification complete” message will be displayed on the “Output Window”


. Now check the operation of the project apply adjustments if needed and repeat above steps.

3.3.2. Troubleshooting.
If you see “Target Device ID (0x0)” error, Click Cancel.

Check the following:


 Check your programmer connection. MCLR, PGD, PGC …….
 Make sure that the microcontroller connected is the same with the one selected on
MPLAB X.
 Check the voltages on VDD & VSS pins.
 Check the polarity on power pins.
 Check if the IC is not burnt.
If mistakes are corrected, repeat programming steps.
Digital Systems III, Practical Manual 16
Experiment 1 LED Interface
Learning Objectives:
After completing the chapter, you must be able:
 To design and implement an embedded system based project.
 To target specific port or specific pin on a port.
 To create and call functions/subroutines to perform tasks in the main program.
 To apply basic and advanced instructions using C language or Assembly
language.

EQUIPMENT
Tools Components
5V Power supply 1 x PIC18F458 microcontroller
1 x Side Cutter 1 x 4MHz Crystal
1 x Pliers 2 x 22pF Capacitors
5 x Male to Male Jumper wires 1 x 10kΩ Resistor
Breadboard 8 x LEDs
Breadboard wires 8 x 220-470Ω Resistors
Digital Multimeter
PICkit 3 Programmer/Debugger
PIC18F458 Datasheet
USB MEMORY STICK!!

Example 2: Turn On 1 LED


Pre-practicals:
1. Type the code on Notepad. Include your name, date, brief description of the code and
your own comments.
+5V

RB0
MCLR 470
10k RB1
470
RB2
PIC18F458

Vdd 470
Vss RB3
470
RB4
470
RB5
470
RB6
470
RB7
470
OSC1 OSC2

4MHz
22pF 22pF

Figure 1

Digital Systems III, Practical Manual 17


In the Lab:
2. Connect the circuit and all required pins on the breadboard. Connect 8 LEDs on
PORTB pins.
3. Apply steps from LAB 1.
4. Open Pre-prac saved on Notepad. Copy the code and Paste it in the Source file on
MPLAB X.
5. Compile and troubleshoot if necessary.
6. Apply steps from LAB 2 and simulate the circuit.
7. Apply steps from LAB 3. Use a multimeter to measure the voltage of your power
supply before using it.
8. Edit the code to use different pins and repeat steps 5-7.
You must be able to explain all the processes and what the code does.

Digital Systems III, Practical Manual 18


Example 3: Turn On 8 LEDs
Pre-practicals:
1. Type the code on Notepad. Include your name, date, brief description of the code and
your own comments.
Use the same circuit in Figure 1.

In the Lab:
2. Connect the circuit and all required pins on the breadboard. Connect 8 LEDs on
PORTB pins.
3. Apply steps from LAB 1.
4. Open Pre-prac saved on Notepad. Copy the code and Paste it in the Source file on
MPLAB X.
5. Compile and troubleshoot if necessary.
6. Apply steps from LAB 2 and simulate the circuit.
7. Apply steps from LAB 3. Use a multimeter to measure the voltage of your power
supply before using it.
8. Edit the code to use different ports and repeat steps 5-7.
You must be able to explain all the processes and what the code does.

Digital Systems III, Practical Manual 19


Example 4: Delay Loop, Subroutines & Functions
Pre-practicals:
1. Type the code on Notepad. Include your name, date, brief description of the code and
your own comments.
Use the same circuit in Figure 1.

Missing text……proceed to the next page.

Digital Systems III, Practical Manual 20


Missing text……proceed to the next page.

Digital Systems III, Practical Manual 21


In the Lab:
2. Connect the circuit and all required pins on the breadboard. Connect 8 LEDs on
PORTB pins.
3. Apply steps from LAB 1.
4. Open Pre-prac saved on Notepad. Copy the code and Paste it in the Source file on
MPLAB X.
5. Compile and troubleshoot if necessary.
6. Apply steps from LAB 2 and simulate the circuit.
7. Apply steps from LAB 3. Use a multimeter to measure the voltage of your power
supply before using it.
8. Edit FLASH, COUNT functions/subroutines to perform differently. Call one
function at a time for better understanding and repeat steps 5-7 for each
function. You must be able to explain all the processes and what the code does.
Reference: Datasheet “PIC18F458” SECTION 9 & 25.
Reference: Book “Programming Microcontrollers in C 2 nd Edition - Ted Van Sickle” CHAPTER1.
Reference: Book “PIC Microcontroller and Embedded Systems – MA. Mazidi” CHAPTER 2,3,4,7.
Reference: Book “PIC Projects and Applications using C 3 rd Edition - David W. Smith” CHAPTER 2 & 3.
=========================END of EXPERIMENT========================
Digital Systems III, Practical Manual 22
Experiment 2 Switch Interface
Learning Objectives:
After completing the chapter, you must be able:
 To design and implement an embedded system based project.
 To read a switch or switches connected on specific pin(s) on a port at random.
 To label inputs/outputs, apply program flow control functions using C language or
Assembly language.

EQUIPMENT
Tools Components
5V Power supply 1 x PIC18F458 microcontroller
1 x Side Cutter 1 x 4MHz Crystal
1 x Pliers 2 x 22pF Capacitors
5 x Male to Male Jumper wires 3 x 10kΩ Resistor
Breadboard 8 x LEDs
Breadboard wires 8 x 220-470Ω Resistors
Digital Multimeter 2 x Push Button switch
PICkit 3 Programmer/Debugger
PIC18F458 Datasheet
USB MEMORY STICK!!

Example 5: Read A Switch


Pre-practicals:
1. Type the code on Notepad. Include your name, date, brief description of the code and
your own comments.
+5V

RB0
MCLR 470
10k RB1
470
RB2
PIC18F458

Vdd 470
Vss RB3
470
RB4
470
10k RB5
470
RA0 RB6
470
RB7
470
OSC1 OSC2
SW1

4MHz
22pF 22pF

Figure 2
Digital Systems III, Practical Manual 23
In the Lab:
2. Connect the circuit and all required pins on the breadboard. Connect 8 LEDs on
PORTB pins and switch is connected on PORTA pin.
Digital Systems III, Practical Manual 24
3. Apply steps from LAB 1.
4. Open Pre-prac saved on Notepad. Copy the code and Paste it in the Source file on
MPLAB X.
5. Compile and troubleshoot if necessary.
6. Apply steps from LAB 2 and simulate the circuit.
7. Apply steps from LAB 3. Use a multimeter to measure the voltage of your power
supply before using it.
8. Edit the code to use different pins, label them and repeat steps 5-7.
You must be able to explain all the processes and what the code does.

Example 6: Read Multiple Switches


Pre-practicals:
1. Type the code on Notepad. Include your name, date, brief description of the code and
your own comments.
+5V

RB0
MCLR 470
10k RB1
470
RB2
PIC18F458

Vdd 470
Vss RB3
470
RB4
470
10k 10k RB5
470
RA0 RB6
470
RA1 RB7
470
OSC1 OSC2
SW2 SW1

4MHz
22pF 22pF

Figure 3

Digital Systems III, Practical Manual 25


Digital Systems III, Practical Manual 26
In the Lab:
2. Connect the circuit and all required pins on the breadboard. Connect 8 LEDs on
PORTB pins, Switch 1 to RA0 and Switch 2 to RA1.
3. Apply steps from LAB 1.
4. Open Pre-prac saved on Notepad. Copy the code and Paste it in the Source file on
MPLAB X.
5. Compile and troubleshoot if necessary.
6. Apply steps from LAB 2 and simulate the circuit.
7. Apply steps from LAB 3. Use a multimeter to measure the voltage of your power
supply before using it.
8. Edit the code to use different pins and repeat steps 5-7.
You must be able to explain all the processes and what the code does.

Reference: Datasheet “PIC18F458” SECTION 9 & 25.


Reference: Book “Programming Microcontrollers in C 2 nd Edition - Ted Van Sickle” CHAPTER1.
Reference: Book “PIC Microcontroller and Embedded Systems – MA. Mazidi” CHAPTER 4 & 7.
Reference: Book “PIC Projects and Applications using C 3rd Edition - David W. Smith” CHAPTER 4.
=========================END of EXPERIMENT========================

Digital Systems III, Practical Manual 27


Experiment 3 7-Segment Interface
Learning Objectives:
After completing the chapter, you must be able:
 To design and implement an embedded system based project.
 To differentiate common cathode and common anode 7-segment display interface.
 To create a display table and use it to generate hexadecimal values for displaying
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F on the 7-segment display.
 To apply basic and advanced instructions using C language or Assembly
language.
EQUIPMENT
Tools Components
5V Power supply 1 x PIC18F458 microcontroller
1 x Side Cutter 1 x 4MHz Crystal
1 x Pliers 2 x 22pF Capacitors
5 x Male to Male Jumper wires 3 x 10kΩ Resistor
Breadboard 1 x 7-segment display common cathode
Breadboard wires 8 x 220-470Ω Resistors
Digital Multimeter
PICkit 3 Programmer/Debugger
PIC18F458 Datasheet
USB MEMORY STICK!!

Example 7: 7-Segment Display (Lesson 6)


Pre-practical’s:
1. Type the code on Notepad. Include your name, date, brief description of the code and
your own comments.
+5V

RB0 A
MCLR 470
10k RB1 B
470
RB2
PIC18F458

C
Vdd 470
Vss RB3 D
470
RB4 E
470
RB5 F
470
RA0 RB6 G
470
RA1 RB7 C
POT=10k 470
OSC1 OSC2

4MHz
22pF 22pF

Figure 4

Digital Systems III, Practical Manual 28


Missing text……proceed to the next page.

Digital Systems III, Practical Manual 29


In the Lab:
2. Connect the circuit and all required pins on the breadboard. Connect the 7-segnment
pins to PORTB pins.
3. Apply steps from LAB 1.
4. Open Pre-Prac saved on Notepad. Copy the code and Paste it in the Source file on
MPLAB X.
5. Compile and troubleshoot if necessary.
6. Apply steps from LAB 2 and simulate the circuit.
7. Apply steps from LAB 3. Use a multimeter to measure the voltage of your power
supply before using it.
8. Edit the code to use different ports and repeat steps 5-7.
You must be able to explain all the processes and what the code does.

Reference: Datasheet “PIC18F458” SECTION 9 & 25.


Reference: Book “Programming Microcontrollers in C 2 nd Edition - Ted Van Sickle” CHAPTER1.
Reference: Book “PIC Microcontroller and Embedded Systems – MA. Mazidi” CHAPTER 4 & 6.
=========================END of EXPERIMENT========================

Digital Systems III, Practical Manual 30


Experiment 4 Keypad Interface
Learning Objectives:
After completing the chapter, you must be able:
 To design and implement an embedded system based project.
 To scan if 1,2,3,4,5,6,7,8,9,*,0,# keys are pressed from 3 x 4 matrix keypad.
 To apply basic and advanced instructions using C language or Assembly
language.
EQUIPMENT
Tools Components
5V Power supply 1 x PIC18F458 microcontroller
1 x Side Cutter 1 x 4MHz Crystal
1 x Pliers 2 x 22pF Capacitors
5 x Male to Male Jumper wires 5 x 10kΩ Resistor
Breadboard 4 x LEDs
Breadboard wires 4 x 220-470Ω Resistors
Digital Multimeter 1 x (3x4) Keypad
PICkit 3 Programmer/Debugger
PIC18F458 Datasheet
USB MEMORY STICK!!

Example 8: Keypad Interface (Lesson 7)


Pre-practical’s:
1. Type the code on Notepad. Include your name, date, brief description of the code and
your own comments.
+5V

_____
MCLR
10k
RB0 RD0
470
PIC18F458

RB1
RB2 RD1
470
RB4
1 2 3
RB5 RD2
470
4 5 6 RB6
7 8 9 RB7 RD3
470
0 # OSC1 OSC2
*
1 2
10k 10k 10k 10k
4MHz
22pF 22pF
+5V

Figure 4

Digital Systems III, Practical Manual 31


Missing text……proceed to the next page.

Digital Systems III, Practical Manual 32


Missing text……proceed to the next page.

Digital Systems III, Practical Manual 33


Missing text……proceed to the next page.

Digital Systems III, Practical Manual 34


In the Lab:
2. Connect the circuit and all required pins on the breadboard. Connect 4 LEDs on
PORTD pins. Connect keypad Column 1 to RB0, Column 2 to RB1, Column 3 to
RB2, Row A to RB4, Row B to RB5, Row C to RB6 and Row D to RB7.
3. Apply steps from LAB 1.
4. Open Pre-Prac saved on Notepad. Copy the code and Paste it in the Source file on
MPLAB X.
5. Compile and troubleshoot if necessary.
6. Apply steps from LAB 2 and simulate the circuit.
7. Apply steps from LAB 3. Use a multimeter to measure the voltage of your power
supply before using it.
8. Edit the code to use different pins and repeat steps 5-7.
You must be able to explain all the processes and what the code does.

Reference: Datasheet “PIC18F458” SECTION 9 & 25.


Reference: Book “PIC Microcontroller and Embedded Systems – MA. Mazidi” CHAPTER 7 & 12.
Reference: Book “PIC Projects and Applications using C 3 rd Edition - David W. Smith” CHAPTER 5
=========================END of EXPERIMENT========================

Digital Systems III, Practical Manual 35


Experiment 5 LCD Interface
Learning Objectives:
After completing the chapter, you must be able:
 To design and implement an embedded system based project.
 To apply basic and advanced instructions using C language or Assembly language
to control and display a text on the LCD when connected to any port.

EQUIPMENT
Tools Components
5V Power supply 1 x PIC18F458 microcontroller
1 x Side Cutter 1 x 4MHz Crystal
1 x Pliers 2 x 22pF Capacitors
5 x Male to Male Jumper wires 1 x 10kΩ Resistor
Breadboard 1 x Liquid Crystal Display (16x2)
Breadboard wires
Digital Multimeter
PICkit 3 Programmer/Debugger
PIC18F458 Datasheet
USB MEMORY STICK!!

Example 9: LCD Interface (Lesson 8)


Pre-practicals:
1. Type the code on Notepad. Include your name, date, brief description of the code and
your own comments.

16X2 LCD
Vee

RW
Vss
Vcc

D0
D1
D2
D3
D4
D5
D6
D7
RS
E

+5V

RB0
RD6
RD7

MCLR
10k RB1
RB2
PIC18F458

Vdd
Vss RB3
RB4
RB5
RA0 RB6
RA1 RB7
OSC1 OSC2

4MHz
22pF 22pF

Figure 5
Digital Systems III, Practical Manual 36
Missing text……proceed to the next page.
Digital Systems III, Practical Manual 37
Missing text……proceed to the next page.

Digital Systems III, Practical Manual 38


In the Lab:
2. Connect the circuit and all required pins on the breadboard. Connect LCD D0-D7 on
PORTB pins. Connect LCD RS & E pins to RD6 and RD7. LCD RW pin must be
grounded.
3. Apply steps from LAB 1.
4. Open Pre-prac saved on Notepad. Copy the code and Paste it in the Source file on
MPLAB X.
5. Compile and troubleshoot if necessary.
6. Apply steps from LAB 2 and simulate the circuit.
7. Apply steps from LAB 3. Use a multimeter to measure the voltage of your power
supply before using it.
8. Edit the code to start displaying messages at the center of the LCD or on the
second line and repeat steps 5-7.
You must be able to explain all the processes and what the code does.
Reference: Datasheet “LMB162ABC-Manual”
Reference: Datasheet “PIC18F458” SECTION 9 & 25.
Reference: Book “PIC Microcontroller and Embedded Systems – MA. Mazidi” CHAPTER 12.
Reference: Book “PIC Projects and Applications using C 3 rd Edition - David W. Smith” CHAPTER 7.
=========================END of EXPERIMENT========================

Digital Systems III, Practical Manual 39


APPENDIX: A PIC18F458 PIN LAYOUT & PERIPHERAL FEATURES

IMPORTANT PINS:
Pin 1: Master Clear pin. It must be connected to +5V through a resistor with a value
between 4.7kΩ & 10kΩ.
Pin 11&32: VDD pins. These pins must be connected direct to +5V. These pins supply
power to the microcontroller.
Pin 12&31: VSS pins. These pins must be connected direct to Ground. These pins supply
power to the microcontroller.
Pin 13&14: OSC1 & OSC2 pins. These are oscillator pins which connects a crystal with a
microcontroller. See picture below.

Digital Systems III, Practical Manual 40


40-Pin High-Performance, Enhanced Flash
Microcontrollers with CAN
High-Performance RISC CPU: Advanced Analog Features:
 Linear program memory addressing up to 2  10-bit, up to 8-channel Analog-to-Digital Converter
Mbytes module (A/D) with:
 Linear data memory addressing to 4 Kbytes - Conversion available during Sleep
 Up to 10 MIPS operation - Up to 8 channels available
 DC – 40 MHz clock input  Analog Comparator module:
 4 MHz-10 MHz oscillator/clock input with PLL - Programmable input and output multiplexing
active  Comparator Voltage Reference module
 16-bit wide instructions, 8-bit wide data path  Programmable Low-Voltage Detection (LVD)
 Priority levels for interrupts module:
 8 x 8 Single-Cycle Hardware Multiplier - Supports interrupt-On-Low-Voltage Detection
 Programmable Brown-out Reset (BOR)
Peripheral Features: CAN bus Module Features:
 High current sink/source 25 mA/25 mA  Complies with ISO CAN Conformance Test
 Three external interrupt pins  Message bit rates up to 1 Mbps
 Timer0 module: 8-bit/16-bit timer/counter with  Conforms to CAN 2.0B Active Spec with:
8-bit programmable prescaler - 29-bit Identifier Fields
 Timer1 module: 16-bit timer/counter - 8-byte message length
 Timer2 module: 8-bit timer/counter with 8-bit - 3 Transmit Message Buffers with prioritization
period register (timer base for PWM) - 2 Receive Message Buffers
 Timer3 module: 16-bit timer/counter - 6 full, 29-bit Acceptance Filters
 Secondary oscillator clock option – - Prioritization of Acceptance Filters
Timer1/Timer3 - Multiple Receive Buffers for High Priority
 Capture/Compare/PWM (CCP) modules; CCP Messages to prevent loss due to overflow
pins can be configured as: - Advanced Error Management Features
- Capture input: 16-bit, max resolution 6.25 ns Special Microcontroller Features:
- Compare: 16-bit, max resolution 100 ns (Tcy)  Power-on Reset (POR), Power-up Timer (PWRT)
- PWM output: PWM resolution is 1 to 10-bit and Oscillator Start-up Timer (OST)
Max. PWM freq. @:8-bit resolution =156kHz  Watchdog Timer (WDT) with its own on-chip RC
10-bit resolution =39 kHz oscillator
 Enhanced CCP module which has all the  Programmable code protection
features of the standard CCP module, but also  Power-saving Sleep mode
has the following features for advanced motor
 Selectable oscillator options, including:
control:
- 4x Phase Lock Loop (PLL) of primary oscillator
- 1, 2 or 4 PWM outputs
- Secondary Oscillator (32kHz) clock input
- Selectable PWM polarity
 In-Circuit Serial ProgrammingTM (ICSPTM) via two
- Programmable PWM dead time
pins
Digital Systems III, Practical Manual 41
 Master Synchronous Serial Port (MSSP) with Flash Technology:
two modes of operation:
 Low-power, high-speed Enhanced Flash
- 3-wire SPITM (Supports all 4 SPI modes)
technology
- I2CTM Master and Slave mode
 Fully static design
 Addressable USART module:
 Wide operating voltage range (2.0V to 5.5V)
- Supports interrupt-on-address bit
 Industrial and Extended temperature ranges

Reference: PIC18FXX8 Data Sheet; 28/40-Pin High-Performance Microcontrollers with


CAN Module – DS41159E

Digital Systems III, Practical Manual 42


APPENDIX: B PICkit 3 PIN LAYOUT
PICkitTM 3 MCU PROGRAMMER/DEBUGGER

PICkitTM 3 PROGRAMMER PINOUT

Reference: PICkitTM 3 Programmer/Debugger User’s Guide – DS51795A

========================== {The END} ============================


Digital Systems III, Practical Manual 43

You might also like