0% found this document useful (0 votes)
5 views44 pages

Microprocessor Lab Manual

The document is a practical workbook for the EE-222 Microprocessor Systems course at NUST-Pakistan, detailing various laboratory experiments related to microprocessor systems. It includes experiments on interfacing ROM and RAM, designing an Arithmetic Logic Unit, and programming in Assembly and C languages. Each lab outlines objectives, requirements, and tasks to be completed, focusing on hands-on learning in microprocessor applications.

Uploaded by

crafterreal99
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
0% found this document useful (0 votes)
5 views44 pages

Microprocessor Lab Manual

The document is a practical workbook for the EE-222 Microprocessor Systems course at NUST-Pakistan, detailing various laboratory experiments related to microprocessor systems. It includes experiments on interfacing ROM and RAM, designing an Arithmetic Logic Unit, and programming in Assembly and C languages. Each lab outlines objectives, requirements, and tasks to be completed, focusing on hands-on learning in microprocessor applications.

Uploaded by

crafterreal99
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

EE Department Microprocessor Systems

PRACTICAL WORK BOOK


For The Course
EE-222 Microprocessor Systems

For
B.E. Electrical Engineering

Name
Registration No.
Degree/Syndicate

Complied By: Checked By:


Muhammad Ali Waris Khan Dr Usman Ali

DEPARTMENT OF ELECTRICAL ENGINEERING


College of Electrical & Mechanical Engineering (CEME), NUST-Pakistan

CEME (NUST), Rawalpindi 1


EE-222 Microprocessor Systems
List of Experiments

[Link]. EXPERIMENT

01 Read-only-memory (ROM) initialization and data reading

02 Random-access-memory (RAM) data write and read

03 Design Of Arithmetic Logic Unit

04 Design of address decoding circuit for memories

05 Branch, Call & I/O instructions in Assembly language

06 Arithmetic & Logic Instructions in Assembly language

07 Compare, Rotate & Indirect Addressing in Assembly Language

08 PIC Programming in C language

09 AVR Programming in C language

10 Generating square wave using timer

11 Introduction to hardware

12 LCD/7-Segment Display Interfacing (Open ended lab)

13 Serial communication

14 Data Acquisition using ADC


Lab 1: Interfacing Of ROM in Proteus

Conducted on: Submitted on:


Instructor: Lab Engineer:
1)
2)
3)

Aim
Interfacing memory chip, ROM in Proteus.

Requirements:

74HC163 (counter), 27C512 (ROM)

Theory

In digital systems, there are two types of memories: 1. RAM 2. ROM

ROM:

Read-only memory is a memory device in which permanent binary information is stored. The number of
words in a ROM is determined from the k address input lines needed to specify the 2k words.

Task:

Write some content in ROM memory by a binary format file, apply the counter outputs to the address
lines of ROM and read the contents via Memory chip.
Lab 2: Interfacing Of RAM in Proteus

Conducted on: Submitted on:


Instructor: Lab Engineer:
1)
2)
3)

Aim
Interfacing memory chip, RAM in Proteus.

Requirements:

74HC163 (counter), 27C512 (ROM), RAM (IS61C1024AL-12JI) ,Multiplexer (74HC157).

Theory

In digital systems, there are two types of memories: 1. RAM 2. ROM

RAM:

Memory unit: Stores binary information in groups of bits called words. Memory word: group of 1’s
and 0’s and may represent a number, character(s), instruction, or other binary-coded information. Most
computer memories use words that are multiples of 8 bits (byte ). 32-bit word ‡ 4 bytes. Each word in
memory is assigned an address 0 up to 2k – 1 (k = # of address lines).
To transfer a new word to be stored into memory:

1. Apply the binary address of the word to address lines.

2. Apply the data bits that must be stored in memory to the data input lines.

3. Activate the write input.

To transfer a stored word out of memory:

1. Apply the binary address of the word to address lines.

2. Activate the read input.

Task:

Design a schematic that loads data from ROM to RAM starting from FFFFH,0000H,0001H to FFFEH

At FFFEH it stops loading.

Give a ram address you should see the data of corresponding address will be shown in the output of
RAM

That means data from ROM has been saved to RAM.


Lab 3: Design Of Arithmetic Logic Unit

Conducted on: Submitted on:

1)
2)
3)

Instructor: Lab Engineer:

Aim
Design and Implementation of 4 bit Arithmetic Logic Unit.

Requirements:

Ful adders, Multiplexers, Registers, etc.

Theory

An Arithmetic Logic Unit (ALU) is a circuit that does arithmetic, such as addition, subtraction,
set‐less‐than, bit‐wise AND, bit‐wise OR, etc. The ALU you will design is a combinational circuit that
operates on 4‐bit numbers. It has two inputs A and B, and an output Y. It has four operations that can be
selected: add, subtract, set‐less‐than, and bit‐wise AND. To select the operation, the ALU has a 2‐bit
select input Sel which selects as follows

• Sel = 00: operation = add


• Sel = 01: operation = sub
• Sel = 10: operation = set‐less‐than
• Sel = 11: operation = bit‐wise AND
Your circuit will also have three 4‐bit registers: RegA, RegB, and RegY. They are all synchronized with
the clock signal. Mux1 Mux2 will select the operands, the result is to be shown on seven segment
display.

Block Diagram:
Lab 4: Address Decoding

Conducted on: Submitted on:


Instructor: Lab Engineer:
1)
2)
3)

Aim
Implementing address decoding using NAND gates.

Requirements:

74HC163 (counter), 27C512 (ROM),RAM ICs, NAND IC

Theory

With the information of desired address locations, It is the job of a decoder circuitry to locate the memory
chip to where desired data is to be stored. We look at the use of NAND gate IC as decoders:

The Address Information is taken from the ROM ICS, we will be needing a cascade of ROM ICs to make
a 20 bit address bus for the RAM ICs.
TASK:

Make the following circuitry to implement address decoding.

Address bus 20bit

ROM1
ROM1
Decoder
Cct1
Binary CS1
Counter

ROM2

Decoder
ROM2
Cct2
CS2
ROM3

of RAM1

Similarly ,

Of RAM2
Lab#5: Branch, call and I/O instructions in Assembly language

GROUP MEMBERS 1.

2.

3.

DATE

INSTRUCTOR

Requirements:
PC with MPLAB‐X, version 5.35 installed

Theory:
1) Branching instructions:
They are used to repeat a sequence of instructions or an operation a certain number of times.
Short jump instructions are:

Long jump instructions are:


GOTO, 32 bit, covers 1M memory space
BRA (branch), 16 bit, covers ±1K space
They are usually used witn increment and decrement instructions given below:
Example 1: Simple loop using DECFSZ instruction

Example 2: Simple loop using BNZ instruction


Example 3: Nested loop using BNZ instruction

Flow chart
2) Call instructions:
CALL, RCALL instructions are used to call a subroutine. They work along with RETURN instruction
Example 4:

3) PORT registers and I/O instructions:


Three SFRs associated to each port: PORTx, TRISx and LATx.
The TRISx is used to make a given port an input or output port.
To make a port an output, we write 0s to the TRISx register.
To make a port an input, we write 1s to the TRISx register.
Unless we activate the TRIS bit (set it to zero), the data will not go from the port register to the pins of the
PIC.
Example:

Task 1
Write program (using unconditional branches) for nested loop (level 3) for toggling pin RD1 10000
times. Show results on circuit simulator.
Task 2
Write program (using conditional branches) for nested loop (level 3) for toggling pin RD1 10000
times. Show results on circuit simulator.
Task3
Write a delay subroutine and use it to toggle an LED connected at RB0 pin. Show results on circuit
simulator.
Lab#6: Arithmetic and logic instructions in assembly language
GROUP MEMBERS 1.

2.
3.
DATE
INSTRUCTOR

Aim:
Execution of addition, subtraction, multiplication, division and logic operations on following types
of numbers in assemble language:
1) Unsigned 8‐bit
2) Unsigned 16‐bit

Theory:
Arithmetic instructions:

ADDLW
The ADDLW instruction has the following format: ADDLW K ; ADD literal value K to WREG.
To add two numbers such as 25H and 34H, the code is:
MOVLW 25H ; load 25H into WREG
ADDLW 34H ; add value 34 to W (W = W + 34H)
Executing the above lines results in WREG = 59H (25H + 34H = 59H)

ADDWF
Instruction "ADDWF fileReg, d" allows the addition of WREG and individual bytes residing in RAM
locations of the file register. For example:
MOVLW 0x10; => WREG = 0x10
MOVWF 0x20; => FileReg[0x20] = WREG = 0x10
MOVLW 0x11; => WREG = 0x11
ADDWF 0x20, ‘w’; => WREG = FileReg[0x20] + WREG = (0x10 + 0x11)
ADDWF 0x20, ‘f’; => FileReg[0x20] = FileReg[0x20] + WREG
ADDWFC
When adding two 16‐bit data operands, we need to be concerned with the propagation of a carry
from the lower byte to the higher byte. This is called multibyte addition to distinguish it from the
addition of individual bytes. The instruction ADDWFC (ADDW and fileReg with carry) is used on such
occasions.

SUBLW K (WREG = K‐ WREG)


In subtraction, the PIC microcontrollers use the 2's complement method. In this method the PIC
uses adder circuitry to perform the subtraction command. Assuming that the PIC is executing a
simple subtract instruction and that C = 0 prior to the execution of the instruction, one can
summarize the steps of the hardware of the CPU in executing the SUBLW instruction for unsigned
numbers as follows:
l. Take the 2's complement of the subtrahend (WREG operand).
2. Add it to the minuend (K operand).

SUBWFB (dest = file Reg‐ W‐ Borrow) subtract with borrow


This instruction is used for multibyte numbers and will take care of the borrowof the lower byte. If
C = 0 prior to executing the SUBWFB instruction, it also subtracts 1 from the result.

Example 16‐bit addition


Example Subtraction of 8‐bit numbers

Example Subtraction of 16‐bit numbers


Multiplication of unsigned numbers
MULLW K
W x K and 16‐bit is result is in PRODH:PRODL
MULLWF
PRODH:PRODL =F x W

Example:

Division of unsigned numbers

Example:

LOGIC INSTRUCTIONS

Example:
Example:

TASK 1
Save two 16 bit unsigned numbers on location starting from address 10H and 20H
respectively, ADD them and save result on location starting from address 30H.

TASK 2
Save two 16 bit unsigned numbers on location starting from address 10H and 20H
respectively, Subtract them and save result on location starting from address 30H. Use
overflow flag to check validity of result.

TASK 3
Save two 8 bit signed numbers on location starting from address 10H and 11H respectively,
Multiply them and save result on location starting from address 20H.

TASK 4
Perform Division of two 8 bit unsigned numbers and store the result on location
starting from 20H.
Lab#7: Compare, rotate and indirect addressing mode
instructions in assembly language
GROUP MEMBERS 1.

2.
3.
DATE
INSTRUCTOR

Aim
1) Execute compare and rotate instructions on unsigned 8‐bit data.
2) Execute Register indirect Addressing mode instructions to read and write data from RAM/ROM.

Theory
Compare instructions

Example:
Rotate instructions
1. Rotate fileReg right (no carry)
RRNCF fileReg, d
2. Rotate fileReg left (no carry)
RLNCF fileReg, d
3. Rotate fileReg right through carry
RRCF fileReg, d
4. Rotate fileReg left through carry
RLCF fileReg, d

Example:

Register Indirect Addressing Mode (RAM)


In the register indirect addressing mode, a register is used as a pointer to the data RAM
location. In the PICI8, three registers are used for this purpose: FSRO, FSRI, and FSR2. FSR stands
for file select register and must not be confused with SFR (special function register). The FSR is a
12‐bit register allowing access to the entire 4096 bytes of data RAM space in the PIC18. We use
LFSR (load FSR) to load the RAM address. In other words, when FSRx are used as pointers, they
must be loaded first with the RAM addresses as shown below
LFSR 1, Ox40 ;loadFSRl with Ox40
LFSR 2, Ox6F ;load FSR2 with Ox6F
Because FSR0, FSR1, and FSR2 are 12‐bit registers they cannot fit into the SFR address space
unless they are split into pieces of an 8‐bit size. That is exactly what PIC I 8 has done. The FSR
registers have the low‐byte and high‐byte parts called FSRxL and FSRxH, as shown in the SFR
table of Table 6‐1. In Table 6‐1 we see FSROL and FSROH, representing the low and high parts of
the 12‐bit FSRO register. Note that the FSRxH is only 4‐bit and the upper 4 bits are not used.
Another register associated with the register indirect addressing mode is the INDF (indirect
register). Each of the FSRO, FSRl, and FSR2 registers has an INDF register associated with it, and
these are called INDFO, INDFI, and INDF2. When we move data into INDFx we are moving data
into a RAM location pointed to by the FSR. In the same way, when we read data from the INDF
register, we are reading data from a RAM location pointed to by the FSR. This is shown below.
LFSR 0, Ox30 ;FSR0 = 30H RAM location pointer
MOVWF INDFO ;copy contents of WREG into RAM
;location whose address is held by
;12‐bit FSRO register
Auto‐increment option for FSR
Because the FSR is a 12‐bit register, it can go from 000 to FFFH, which covers the entire 4K RAM
space of the PIC18. Using the "INCF FSROL, p" instruction to increment the pointer can cause a
problem when an address such as 5FFH is incremented. The instruction "INCF FSROL, F" will not
propagate the carry into the FSRIH register. The PIC 18 gives us theoptions of auto‐increment
and auto‐decrement for FSRn to overcome this problem.

Example:
Write a program to copy a block of 5 bytes of data from RAM locations starting at 30Hto RAM
locations starting at 60H.
COUNTREG EQU 0x10
CNTVAL EQU D'5'
MOVLW CNTVAL
MOVWF COUNTREG
LFSR 0,0x30
LFSR 1,0x60
B3 MOVF POSTINC0,W
MOVWF POSTINC1
DECF COUNTREG,F
BNZ B3

TASK 1
Write a program to find smallest of three values 27, 54, 19.

TASK 2
Write a program to transfer value 0x54 serially at RD0 pin. Send two 1's at start and end. Send
the LSB first.

TASK 3 (OPTIONAL)
Write a program to copy a block of 10 bytes of data from RAM locations starting at 0x20 to RAM
locations starting at 30H.
Lab 8: Pic Programming in C

Conducted on: Submitted on:


Instructor:

Lab Engineer:
Group Members

1)
2)
3)

Aim
Understanding writing codes in C for PIC 18F microcontroller

Theory
1) Chapter 7 of PIC Microcontroller and embedded systems by MAZIDI.
2) Data sheet of PIC microcontroller

Equipment
PC with MPLABX and XC8 compiler installed.

Tasks Marks
2) Binary to decimal conversion 4
3) BCD to ASCII conversion 4
Explanation
Reason behind C programming of pic
The following are some of the major reasons for writing programs in C instead of Assembly.
I. It is easier and less time consuming to write in C than in Assembly.
2. C is easier to modify and update.
3. You can use code available in function libraries.
4. C code is portable to other microcontrollers with little or no modification.

Example
Following C code toggles all pins of PORTC and PORTD continuously with an approximate
delay of 250ms

#include <P18F458.h>
voidMSDelay(unsigned int);
void main(vd)
{
TRISC = 0;
TRISD = 0;
while(1)
{
PORTC = 0x55;
PORTD = 0x55;
MSDelay(250);
PORTC = 0xAA;
PORTD = 0xAA;
MSDelay(250);
}
}
voidMSDelay(unsigned intitime)
{
unsignedinti; unsigned char j;
for(i=0;i<itime;i++)
for(j=0;j<165;j++); Show output on proteus
}

Task1
Write a Cl8 program to convert packed BCD to ASCII and display the bytes on PORTB and
PORTC

Task2
Write a C18 program to convert FD hex to decimal and display the digits on PORTB, PORTC,
and PORTD

Task 3: Data Serialization; Write a CI8 program to send out the value 44H serially one bit at a time
via RCO
EE Department Microprocessor Systems

Lab#09 : AVR Programming in C

GROUP MEMBERS 1.
2.
3.
DATE
INSTRUCTOR

PIC18 and AVR, both are 8-bit architectures. This lab focuses on programming of AVR
microcontroller in C language demonstrating difference of both architectures. The AVR is an
8-bit RISC single-chip microcontroller with Harvard architecture that comes with some
standard features such as on-chip program (code) AVRs have some additional features like
ADC, PWM, and different kinds of serial interface such as USART, SPI, I2C (TWI), CAN,
USB, and so on.

CEME (NUST), Rawalpindi 1


EE Department Microprocessor Systems

Example 1(Ports programming):


In AVR, each port has three I/O registers associated with it. They are designated as PORTx,
DDRx, and PINx. For example, for Port B we have PORTB, DDRB, and PINB. Notice that
DDR stands for Data Direction Register, and PIN stands for Port INput pins. To read the data
present at the pins, we should read the PIN register, whereas to send data out to pins we use
the PORTx register. DDRx=0xFF sets PORTx as output.

CEME (NUST), Rawalpindi 2


EE Department Microprocessor Systems

Example 2 (Delays):

Example 3: (Bit Manipulation)

CEME (NUST), Rawalpindi 3


EE Department Microprocessor Systems

Example 4 (Logic Operations):

Example 5: (Shift Operations):

CEME (NUST), Rawalpindi 4


EE Department Microprocessor Systems

Tasks:
1. Write an AVR C program to toggle all bits of Port B 50,000 times.
2. Write an AVR C program to toggle all the pins of Port C continuously with a 10 ms
delay. Use a predefined delay function in library “delay.h”.

CEME (NUST), Rawalpindi 5


EE Department Microprocessor Systems

Lab#10 : Generating Square Wave using Timers

GROUP MEMBERS 1.
2.
3.
DATE
INSTRUCTOR

Aim
At the end of lab student should be able to understand working of timers

Theory
Chapter 9 of PIC Microcontroller and embedded systems by MAZIDI.

Equipment
PC with MPLABX and proteus installed, PICKit3, PIC 18F452, +5v Battery or power
supply, 20 MHz Crystal, 10kΩ Resistor, 1uF Capacitor, 5mm LED, Breadboard
Oscilloscope

Timer 0 16-Bit Timer Programming:


The following are the characteristics and operations of 16-bit mode:

1. It is a 16-bit timer; therefore, it allows values of 0000 to FFFFH to be loaded into the
registers TMR0H and TMR0L.
2. After TMR0H and TMR0L are loaded with a 16-bit initial value, the timer must be
started. This is done by “BSF T0CON, TMR0ON" for Timer 0.
3. After the timer is started, it starts to count up. It counts up until it reaches its limit of
FFFFH. When it rolls over from FFFFH to 0000, it sets HIGH a flag bit called
TMR0IF (timer interrupt flag, which is part of the INTCON register). This timer flag
can be monitored. When this timer flag is raised, one option would be to stop the
timer.
4. After the timer reaches its limit and rolls over, in order to repeat the process, the
registers TMR0H and TMR0L must be reloaded with the original value, and the
TMR0IF flag must be reset to 0 for the next round.

Steps to Program Timer 0 in 16-bit Mode:


To generate a time delay using the Timer mode 16, the following steps are taken:
1. Load the value into the T0CON register indicating which mode (8-bit or 16-bit) is to be
used and the selected prescaler option.
2. Load register TMR0H followed by register TMR0L with initial count values.
3. Start the timer with the instruction "BSF T 0CON, TMR0ON".
4. Keep monitoring the timer flag (TMR0IF) to see if it is raised. Get out of the loop
when TMR0IF becomes high.

CEME (NUST), Rawalpindi 1


EE Department Microprocessor Systems

5. Stop the timer with the instruction "BCF T 0CON, TMR0ON".


6. Clear the TMR0IF flag for the next round.
7. Go back to Step 2 to load TMR0H and TMR0L again. To clarify the above steps, see
Example 9-3. To calculate the exact time delay and the square wave frequency
generated on pin PB5, we need to know the XTAL frequency
8. TMR0L, because the value for TMROH is kept in a temporary register and written to
TMROH when TMROL is loaded. This will prevent any error in counting if the TMR0ON
flag is set HIGH.

Example
Assuming that XTAL = I0 MHz, write a program to generate a square wave with a period of
10ms on pin PORTB.3.

Solution
For a square wave with T = I0 ms we must have a time delay of 5 ms. Because XTAL= I0
MHz, the counter counts up every 0.4us. This means that we need 5 msI 0.4 uS =12,500
clocks.

65,536- 12,500 = 53,036 = CF2CH.

Therefore, we have

TMROH = CF and

TMROL = 2C.

Code
BCF TRISB,3
MOVLW 0x08
MOVWF T0CON
HERE MOVLW 0xCF
MOVWF TMR0H
MOVLW 0x2C
MOVWF TMR0L
BCF INTCON,TMR0IF
CALL DELAY
BTG PORTB,3
BRA HERE
DELAY BSF T0CON,TMR0ON
AGAIN BTFSS INTCON,TMR0IF
BRA AGAIN
BCF T0CON,TMR0ON
RETURN

CEME (NUST), Rawalpindi 2


EE Department Microprocessor Systems

CEME (NUST), Rawalpindi 3


EE Department Microprocessor Systems

Lab#11 : Introduction to Hardware

GROUP MEMBERS 1.
2.
3.
DATE
INSTRUCTOR

Aim
At the end of lab student should be able to program microcontroller IC

Theory
Chapter 8 of PIC Microcontroller and embedded systems by MAZIDI.

Equipment
PC with MPLABX and proteus installed, PICKit3, PIC 18F452, ATMEGA32/Development
Board, USBASP programmer, Bitburner Sodtware. +5v Battery or power
supply, 20 MHz Crystal, 10kΩ Resistor, 1uF Capacitor, 5mm LED, Breadboard
Oscilloscope

LED Blinking using PIC:


Make connection of microcontroller with accessories as shown in figure 1 and figure 2

CEME (NUST), Rawalpindi 1


EE Department Microprocessor Systems

LED Blinking using ATMEGA32:


The following picture shows the AVR development board:

CEME (NUST), Rawalpindi 2


EE Department Microprocessor Systems

The following picture shows the USBASP programmer and its connections:

1. Connect the USBASP to the development board by matching the pins labeled on both
the devices.
2. Connect the USBASP to a computer/Laptop and open the bitburner software. It will
look like the following image.

3. Select the microcontroller(ATMEGA32) and the programmer (USBASP) in the


AVRDUDE tab.

CEME (NUST), Rawalpindi 3


EE Department Microprocessor Systems

4. Write LED blink code in MPLABX and ccreate HEX file.


5. Upload the hex file in bitburner in AVR Memories:
6. Click on write, the hex file will be burnt to the controller and LED on the
corresponding port will start flashing.

Task
Write a program to toggle pin RB1 after every 1 sec. Connect LED to RB1. (first run
simulation in proteus). Show status of the switch by LED connected to RB1.

CEME (NUST), Rawalpindi 4


Lab 12: LCD Interfacing (OEL)

Conducted on: Submitted on:

Instructor:

Lab Engineer:
Group Members
1)
2)
3)

Aim
At the end of lab student should be able to understand working of LCD and using it for
displaying information.

Theory
Chapter 12of PIC Microcontroller and embedded systems by MAZIDI.

Equipment
PC with MPLABX and proteus, Matlab and Vspd/Vspe installed PICKit3, PIC18 generic
board or pic dem2 plus demonstration board, Serial cable, LCD

TaskMarks
1) Display name and registration on LCD 10
Explanation
LCD pin descriptions
LCD (Liquid Crystal Display) display module to PIC microcontroller? LCD is a passive component
that is it does not make any light but just modifies the light passing through it for alphanumeric
displays. LCD is exclusively manufactured to be used withmicrocontrollers, which means that
it cannot be triggered by usual IC circuits Details of particular LCD are given in its data sheet.
Text book may also be consulted here only brief description is given

Control pins
(R/S , R/W , E pins)
The control pin RS determines if the data transfer between the LCD module and an external
microcontroller are actual character data or command/status. When the microcontroller needs
to send commands to LCD or to read the LCD status, it must be pulled low. Similarly, this must
be pulled high if character data is to be sent to and from the LCD module. The direction of data
transfer is controlled by the R/W pin. If it ispulled Low, the commands or character data is
written to the LCD module. And, when it is pulled high, the character data or status information
from the LCD registers is read. Here, we will use one way data transfer, i.e., from
microcontroller to LCD module, so the R/W pin will be grounded permanently. The enable pin
(E) initiates the actual data transfer. When writing to the LCD display, the data is transferred
only on the high to low transition of the E pin.

Power supply pins


(power, ground , contrast pins)
Although most of the LCD module data sheets recommend +5V d.c. supply for operation, some
LCDs may work well for a wider range (3.0 to 5.5 V). The Vdd pin should be connected to the
positive power supply and Vss to ground. Pin 3 is Vee, which is used to adjust the contrast of
the display. In most of the cases, this pin is connected to a voltage between 0 and 2V by using a
preset potentiometer. Data pins Pins 7 to 14 are data lines (D0-D7). Data transfer to and from
the display can be achieved either in 8-bit or 4-bit mode. The 8-bit mode uses all eight data
lines to transfer a byte, whereas, in a 4- bit mode, a byte is transferred as two 4-bit nibbles. In
the latter case, only the upper 4 data lines (D4-D7) are used. This technique is beneficial as this
saves 4 input/output pins of microcontroller.

Circuit Diagrams
Connect LCD to microcontroller according to following connections. Basic connections of
microcontroller are not shown
Task
Make circuit according to the above diagram and write a program to display your name (in first line) and
registration no(in second line).(First run simulation in proteus)
EE Department Microprocessor Systems

Lab#13 : Serial communication with/without interrupts

GROUP MEMBERS 1.
2.
3.
DATE
INSTRUCTOR

Introduction:
RS-232 is used for asynchronous data transmission. Example for 8-bit ascii character ‘A’ =
01000001 transmission diagram is as follows:

RS232 port pin connections:

CEME (NUST), Rawalpindi 1


EE Department Microprocessor Systems

Baud rate setting

TXSTA Reg

CEME (NUST), Rawalpindi 2


EE Department Microprocessor Systems

RCSTA (Receive status and control register)

Programming the PIC18 to transmit data serially:


1. Load TXSTA register with 20h
2. Set TX pin RC6 as output
3. Load SPBRG to set baud rate
4. Set SPEN bit high in RCSTA register to enable serial port
5. Load TXREG with byte to send
6. Monitor the TXIF bit of the PIR1 register to make sure UART is ready for next byte
7. Goto step 5 to transfer next byte
Programming the PIC18 to receive data serially:
1. Load the RCSTA register with the value 90H
2. Load TXSTA register with the value 0H
3. Load SPBRG to set baud rate
4. Set RX pin RC7 as input
5. Monitor RCIF flag bit of the PlR1 to see if an entire character has been received
6. When RClF is raised, move received byte in RCREG register to RAM
7. Goto step 5

CEME (NUST), Rawalpindi 3


EE Department Microprocessor Systems

Tasks:
1. Write a C program to transmit data serially at 9600 bps.
2. Write a C program to receive data serially at 9600 bps.
3. Write a C program to transmit/receive data serially at 9600 bps using interrupts. (Ref:
Program 11-7c of textbook)

CEME (NUST), Rawalpindi 4


Lab 14: Data Acquisition using ADC

Conducted on: Submitted on:

Instructor:

Lab Engineer:
Group Members
1)
2)
3)

Aim
At the end of lab student should be able to understand how to use ADC to digitize
analog signals using PIC microcontrollers and visually see the signals on display.

Theory
Chapter 11 and 13 of PIC Microcontroller and embedded systems by MAZIDI.

Equipment
PC with MPLABX, proteus, PIC 18F4550, BCD 7 Segment Display.
Explanation
Steps in programming the A/D converter using polling
To program the AID converter of the PIC18, the following steps must be taken:
1. Turn on the ADC module of the PICI8 because it is disabled upon power-on reset to save
power. We can use the "BSF ADCONO, ADON" instruction.
2. Make the pin for the selected ADC channel an input pin. We use "BSF TRISA, x." or "BSF
TRISE, x" where x is the channel number.
3. Select voltage reference and A/C input channels. We use registers ADCONO and ADCON1.
4. Select the conversion speed. We use registers ADCONO and ADCONI.
5. Wait for the required acquisition time.
6. Activate the start conversion bit of GO/DONE.
7. Wait for the conversion to be completed by polling the end-of-conversion (GO/DONE) bit.
8. After the GO/DONE bit has gone LOW, read the ADRESL and ADRESH registers to get the
digital data output.
9. Go back to step 5.

TASK STATEMENT
Digitize a sine wave input using the ADC module of the PIC18F4550, convert the resulting
4-bit digital output to hexadecimal format, and display it on a BCD to 7-segment display
module (0–F).

1) Apply Analog Input


o Apply a 1 Hz sine wave of 2 Vpp with a 2V DC offset to AN0 (RA0) of the
PIC18F4550.
o This creates a waveform oscillating between 1V and 3V, safely within the
ADC's 0–5V range.
2) ADC Configuration
a. Configure the ADC to:
i. Sample from AN0
ii. Use left justification (ADFM = 0)
3) Scale to 4-bit BCD Digit
a. Use the 10-bit ADC result (0–1023) and scale it to a 4-bit BCD (0–15)
4) Output to PORTD
a. Send the 4-bit digit directly to PORTD, which is connected to a BCD to 7-
segment decoder.
b. The display will show values from 0 to F (hex) representing sine wave
levels.
5) Simulate in Proteus
a. Use Proteus simulation with:
i. A function generator generating the sine wave connected to RA0.
ii. The PIC18F4550 running your code.
iii. A BCD to 7-segment display connected to PORTD driving a 7-segment
display.

You might also like