Lab Manual 6
Lab Manual 6
Lab Objectives
By the end of this lab, you ought to be able to possess a foundational understanding of
microcontroller programming and system design using Proteus.
PIC Microcontroller
The PIC (Peripheral Interface Controller) microcontroller family, is renowned for its
efficiency and versatility in embedded systems. These microcontrollers are designed to be compact
and low-power, making them ideal for a variety of applications, from consumer electronics to
industrial automation.
The PIC architecture features a range of built-in peripherals, including timers, analog-to-
digital converters, and communication interfaces like UART and SPI, allowing for seamless
interaction with sensors and other devices. This makes PIC microcontrollers highly suitable for
tasks that require precise control and data processing.
PIC18F452 microcontroller has a number of input/output pins which are used for
connection with external devices. It has total 40 pins. Out of these 40 pins, 34 pins can be used as
input output pins. These pins are grouped into five categories which are called PORTS denoted by
A, B, C, D and E.
Registers
Each port has three registers for its operation.
TRIS REGISTER:
TRIS is a data direction register. Setting TRIS bit for corresponding port will let know the
data direction (whether read or write) to microcontroller. Each PORT has its own TRIS register.
For example, for PORT A:
PORT REGISTER:
It reads the levels on the pins of the device and it assigns logic values (0/1) to the ports.
The role of the PORT register is to receive the information from an external source (like a sensor)
or to send information to external elements (like an LCD).
LAT REGISTER:
It is used to hold the output values intended for the I/O pins. It maintains the output state
until explicitly changed.
1. The label is used when you have to jump from any specific location of code to a specific
command so you have to name that command using label.
2. Mnemonic is used for opcode of command like add, mov.
3. Operands are used to mention the registers or constants used by command.
For example:
MOV INSTRUCTION:
MOV instruction simply copies the data from one location into another. This instruction
simply tells the CPU to move or simply copy the source operand data to destination. It has the
following format:
MOV DESTINATION,SOURCE
For example:
Mov A,#55h
Mov R0,A
After these instructions A = R0 = 55h, “#” sign which is also called pound sign is used for
immediate addressing, which means that the number 55h will be copied to register.
MOVWF Instruction: copies the value from WREG to a specified file register in RAM.
Syntax: MOVWF <address>
Examples:
MOVWF 34H ; Copy value from WREG to RAM location 34H
MOVWF PORTB ; Write the value of WREG to the PORTB register
A seven-segment display is a simple electronic display device used to show numbers and
some alphabetic characters. It consists of seven individual LED segments arranged in the shape of
an "8" that can be lit in various combinations to form numbers and letters. The segments are labeled
as a, b, c, d, e, f and g. By selectively illuminating these segments, we can display any of the ten
decimal digits (0–9) and some additional symbols.
Lab Tasks
1. Write a program in MPLAB to set Port B as output. Generate the assembly code for
following:
a) Case 1: Blink the even LEDs of LED bar graph.
b) Case 2: Blink odd LEDs of LED bar graph.
c) Case 3: Blink all LEDs of LED bar graph.
Burn the code onto hex files and design Proteus schematics for all cases.
2. Design a counter starting from 0 and terminating again at 0 (traversing from 0 to 9, then
backwards from 9 to 0).Use seven-segment display for showing the counter. Each number
should be displayed for an appropriate instance of time on the display. Simulate the
program on Proteus.
General Guidelines