0% found this document useful (0 votes)
10 views18 pages

Lab Manual CSE332 Embedded Systems and M

This lab manual outlines a series of experiments for the CSE332 course on Embedded Systems & Microcontroller at Yanbu University College. It includes objectives, activities, and review questions for each lab session, covering topics such as I/O port simulation, interfacing with LCDs, timer programming, interrupt programming, ADC operations, and serial communication with a PC. The manual serves as a comprehensive guide for students to understand and implement various microcontroller functionalities using the MPLAB simulator and development board.

Uploaded by

Manoj Smail
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)
10 views18 pages

Lab Manual CSE332 Embedded Systems and M

This lab manual outlines a series of experiments for the CSE332 course on Embedded Systems & Microcontroller at Yanbu University College. It includes objectives, activities, and review questions for each lab session, covering topics such as I/O port simulation, interfacing with LCDs, timer programming, interrupt programming, ADC operations, and serial communication with a PC. The manual serves as a comprehensive guide for students to understand and implement various microcontroller functionalities using the MPLAB simulator and development board.

Uploaded by

Manoj Smail
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/ 18

Computer Science and Engineering Department

Yanbu University College (Women’s Campus)


The Royal Commission at Yanbu
Kingdom of Saudi Arabia
Academic Year 2015-16
Semester I

Lab Manual

CSE332

Embedded Systems & Microcontroller

Prepared By
Salma Hamoda

January 21, 2016


Lab 1
SIMULATING I/O PORTS

OBJECTIVES:

To examine the I/O port operation using a MPLAB simulator.

REFERENCE:

 Mazidi, McKinlay, and Causey “PIC Microcontroller and Embedded


Systems,”.

MATERIALS:
 MPLAB assembler and simulator &
 Development board HP-488
 PC.

ACTIVITY 1:

Write and compile a program to toggle all the bits of PORTB and PORTA
continuously by sending 55H and AAH to these ports. Put a time delay between
the "on" and "off" states. Then using the simulator, single-step through the
program and examine the ports.

ACTIVITY 2:

Using a simulator, write a program to get a byte of data from PORTA and send
it to PORTB. Also, give a copy of it to FileReg locations 20H and 22H. Place a
short delay between inputting the data from the port and sending it out to
PORT. Single-step the program and examine the ports and registers.

Page 2 of 18
Review Questions:

1. Upon reset, all the ports of the PIC18F are configured as ______ (input,
output).

2. To make all the bits of a port an input port we must write ____ hex to
register______.

3. Which ports of the PIC18 are bits addressable?

4. What does it mean for port to be "read-modify-write"?

5. Write a program to monitor RB4 continuously. When it becomes low, it


sends 55H to PORTC.

6. The PC (program counter) in PIC18 is _______-bits wide. Give the name of


each byte.

Page 3 of 18
Lab 2
TESTING PIC I/O Ports of a PIC

OBJECTIVE:

 To test the PIC and its ports using the development board.
REFERENCE:

Mazidi, McKinlay, and Causey “PIC Microcontroller and Embedded


Systems,”

MATERIALS:

Development board HP-488


MPLAB
Logic probe
ACTIVITY 1:

Test the operation of the ports of your Development board as follows. Write and compile a
program to toggle all the bits of PORTA, and PORTB continuously by sending 55H and AAH to
these ports. The PORTA and PORTB pins are connected to the LED of the Board.
Use your board to watch the bits of the ports toggle on and off. Make sure that the time delay in
between the "on" and "off" states is long enough that you can observe each state clearly.

ACTIVITY 2:

Test the PIC’s ports for input operation as follows. PORTA and PORTB is connected to the push
buttons of on board. Write and run a program to get data from PORTB and send it to PORTA.
Any change of status of the switches connected to PORTB will be instantly reflected on LEDs
connected to PORTA.

Page 4 of 18
Review Questions:

1. Upon reset, all ports of the PIC are configured as ___________ (output,
input).
2. Which port of the PIC18F has ADC channels?

3. Which pin(s) of PORTB in the PIC18 is used for low-voltage-programming


(LVP) by the Development board HP-488 and cannot be used as I/O?

4. In the PIC, explain why we must write "1" to TRISx register in order for the
port to be used for input.

5. Explain why we need to buffer the switches used as input in order to avoid
damaging the PIC port.

6. Explain the different roles played by the PORTC and TRISC registers in I/O
operation.

Page 5 of 18
Lab 3
Interfacing the LCD to a PIC

OBJECTIVES:

To understand the operation modes of an LCD.


To interface and program an LCD to a PIC.

REFERENCES:

Mazidi, McKinlay, and Causey, “The 8051 Microcontroller and Embedded


Systems,”.
Dot Matrix LCD Module: Character-type DMC Series User's Manual by
Optrex Corp.

MATERIALS:

Development board HP-488


MPLAB IDE

ACTIVITY 1:

The LCD module on the Development board HP-488 can be connected to your
PIC through Port B. The LCD connection is done through switching the LCD
switch to ON position.
Write and run a program to display your name on line 1 of the LCD (first name
followed by last name with a space in between). The name should be in the
middle of the line.
Rewrite the program to include three LCD routines; one to send command “void
LCD_Command (void)”, another one to transfer data “void CD_Character(data,
lineNumber)” and another to initiliaze the LCD “void LCD_Initialization
(void)”.

Note: If you are not monitoring the busy flag of the LCD, you will need to add
a 2.50 ms delay in your program to allow for the controller of the LCD to
complete the execution of any instruction sent from the PC. The delay must
be independent of the microprocessor speed. Use the Sleep() function to
generate the delay or create your own
delay routine.

Page 6 of 18
ACTIVITY 2:
Repeat Activity 1 while also putting the year you graduated from high school on
the second line. When you run your program, the LCD should show (for
example):

Omar Mohamed
Graduated in 1978

ACTIVITY 3:

Write an LCD program to display your last name on the first line and the
current year on the second line.
Both should be in the middle of the line.

ACTIVITY 3 (if time permits):

Write a program to get Port B status input (binary number) and put it on the
LCD in hex.

Review Questions:

1. How does the LCD distinguish data from instruction codes when receiving
information at its data pin?

2. To send the instruction code 01 to clear the display, we must make RS = ___.

3. To send letter 'A' to be displayed on the LCD, we must make RS = ____.

4. What is the purpose of the E line? Is it an input or an output as far as the LCD
is concerned?

5. When is the information (code or data) on the LCD pin latched into the LCD?

6. What is the purpose of the BF (busy flag)?

 Demonstrate the lab working to the professor by running the program (the
LCD name).

 Also hand-in a hard-copy printout of code. Be sure to put your name on


the top of the printout in the comment area of the code.

Page 7 of 18
Page 8 of 18
Page 9 of 18
Lab 4
PIC Timer Programming

OBJECTIVES:

To program the PIC timer.


To generate a square wave using the PIC timer.

REFERENCE:

Mazidi, McKinlay, and Causey “PIC Microcontroller and Embedded


Systems,” Chapter 9.

MATERIALS:

Development board HP-488


MPLAB IDE
Oscilloscope

ACTIVITY 1:

Write a program using Timer0 to generate a 500 Hz square wave frequency on


one of the pins of PORTB. Then examine the frequency using the oscilloscope.
Modify the count value to make sure that the frequency is exactly 500 Hz.

ACTIVITY 2:

Write a program using Timer1 to generate a 1 kHz square wave frequency on


one of the pins of PORTB. Then examine the frequency using the oscilloscope.
Modify the count value to make sure that the frequency is exactly 1 kHz.

ACTIVITY 3:

Write a program using Timer0 to generate a 1 kHz and a 2 kHz square wave
frequencies on one of the pins of PORTB. Connect a switch to a pin on PORTB
and use it to select the frequency. Then examine the frequencies using the
oscilloscope. Modify the count value to make sure that the frequencies are
exact.

Page 10 of 18
Review Questions:

1. What is the maximum frequency that can be on generated on Timer0 using


a) 16-bit mode
b) 8-bit mode
if the crystal frequency is 10 MHz? Show your calculation.

2. What is the lowest frequency that can be generated on Timer0 using:


a) 16-bit mode
b) 8-bit mode
if the crystal frequency is 10 MHz? Show your calculation.

3. What is the lowest frequency that can be generated using Timer1 if the
crystal frequency is 10 MHz? Show your calculation.

4. Compare and contrast the features of the Timer0, Timer1, and Timer2.

5. In 16-bit mode, when is TMR0IF set to high?

6. State to which register the TMR0IF belongs to.

7. In 8-bit mode, when is TMR0IF set to high?

Page 11 of 18
Lab 5
Interrupt Programming

OBJECTIVES:

To program the timer interrupt of the PIC.


To program the serial interrupt of the PIC.
To program the hardware interrupt of the PIC.

REFERENCE:

Mazidi, McKinlay, and Causey “PIC Microcontroller and Embedded


Systems,” Chapter 11.

MATERIALS:

Development board HP-488


MPLAB IDE
Square wave generator

Pre Lab: Show to the instructor the answer to following Prelab questions
before you start the lab experiment.

1) List all the registers and flag bits to be used in activity 1.


2) For activity 1, find the contents of T1CON, TMR1H, and TMR1L.
3) List all the registers and flag bits to be used in activity 2.
4) List all the registers and flag bits to be used in activity 3.

ACTIVITY 1:

Write a program to get data from a single bit of RB4 and send it to RB5
continuously while an interrupt will do the following:
One of the timers (Timer 1) will toggle pin RB6 every 100 milliseconds.

ACTIVITY 2:

Add the following interrupt to Activity 1: Connect one of the hardware


interrupt pins (INT0) to a normally high de-bounce SW (or push button switch
connected to RB0) and any time the switch is pressed, a single LED (LED of
RA5) is turned on.

Page 12 of 18
ACTIVITY 3:

Add the following interrupt to Activity 2: A square wave is connected to


hardware interrupt (INT2) and any time a L-to-H pulse comes in, a single LED
(LED of RA6) is turned on. The rate of "On" and "Off" is the same as the square
wave frequency.

Review Questions:

1. For the PIC18F458/4580, name all the interrupts associated with timers and
ADC.

2. In Timer0 16-bit mode, indicate when TMR0IF causes the interrupt.

3. In Timer0 8-bit mode, indicate when TMR0IF causes the interrupt.

4. On reset, all hardware interrupts are ____positive-edge__ (edge, level)


triggered.

5. True or False. On reset, high priority is assigned to all interrupts.

6. True or False. There is only a single interrupt for RB0, RB1, and RB2.

Page 13 of 18
Lab 6
PIC Timer Programming

OBJECTIVES:
To experiment with ADC of PIC.

REFERENCE:
Mazidi, McKinlay, and Causey “PIC Microcontroller and Embedded
Systems,” Chapter 13.

MATERIALS:
Development board HP-488
MPLAB IDE

PreLab:
To be submitted before the start of the lab.
(Review ADC features of the PIC in handout 10 and chapter 13 of the
textbook.)
1. List all the registers and flag bits required to operate the ADC of the PIC.
2. Find the values of the two control registers of the ADC in the activity 1.
3. List the steps to program the ADC of the PIC.

ACTIVITY 1:

The potentiometer RV3 on the development board is connected to the RA1 pin
(configured as input pin).
PIC can be used to measure the analog voltage across the potentiometer. Note
that the jumper J14/1 will need to be in the analogue position to use it. Write a
program to display, the data measured at RA1 pin (the potentiometer output), on
the LCD.
Notice that the ADC output must be converted to decimal and then to ASCII in
order to be displayed on the LCD. As you change the potentiometers, the output
should change, indicating the value of the analog input.

ACTIVITY 2:

In place of a potentiometer, use the cadmium supplied light dependent resistor


sensor on the development board as an analog input. The light sensor consists of
a resistance that decreases as light falling on to it increases. Note that the
jumper J14/0 needs to be in the analogue position to use this sensor.
Change the program in Activity 1 to read the analog values from RA0 pin
(configured as input pin).
Page 14 of 18
Display the measurement on the LCD continuously. Cover the sensor to
decrease the amount of light falling on the sensor and observe its effect on the
value measured.

Review Questions:

1. Define the following terminology in ADC.

(a) Resolution:
(b) Full-scale voltage output:
(c) Settling time

2. Find Vin (input voltage to Port A) for the following binary output number of
the ADC.

(a) 0110011000:
(b) 1000111100

3. To get a smaller step size, we need ADC with ________ (more, less) data bit
inputs.

4. What is a transducer?

5. What is the form of the transducer output?

6. What is preprocessing of transducer signals to be fed into an ADC called?

7. Explain signal conditioning and its role in data acquisition.

Page 15 of 18
Lab 7
PIC Serial Port Programming

OBJECTIVES:

To write a program to transfer data to x86 PC serially.


To write a program to receive data from x86 PC serially.

REFERENCE:

Mazidi, McKinlay, and Causey “PIC Microcontroller and Embedded


Systems,” Chapter 10.

MATERIALS:

Development board HP-488


MPLAB IDE

PreLab:
To be submitted before the start of the lab.
Review PIC18 serial port features in handout 10 and chapter 11 of the textbook.
1. List all the registers and flag bits required to operate the serial port of the
PIC.
2. Find the values of the control and serial port baud registers for Activity 1.
3. List the steps for transmitting data serial program from the PIC.

ACTIVITY 1:

Build the circuit in the Figure 1. Connect your PIC serial port to the x86 PC's
COM1 port. Then write a program to transfer your last name to the PC
continuously. On the PC side you need to use the HyperTerminal program.
Here are the steps to set up HyperTerminal:
1. In Microsoft Windows Accessories, click on HyperTerminal (if you get a
modem installation option, choose "NO").
2. Type a dummy name, and click OK.
3. For "Connect Using" select COM1 and click OK. Use COM2 if COM1 is
used by the mouse.
4. Pick 9600 (or whatever baud rate you programmed the PIC Trainer), 8 bit
data, no parity bit, and 1 stop bit.
5. Change the "Flow Control" to NONE or Xon/Xoff and click OK (definitely
do not choose the hardware option).
Page 16 of 18
After running your PIC serial program, you should see your last name fill the
PC screen.

ACTIVITY 2:

After making sure that Activity 1 works properly, write a program to get data
from the PC and display it on an LCD. As you press a key on the x86 PC's
keyboard, the character is sent to the PIC Trainer serially and is displayed on
LEDs. The characters displayed on LEDs are in ASCII (binary).

ACTIVITY 3:

Modify and run the program in Activity 1 to transfer the data at the highest baud
rate your PIC Trainer allows. Check the crystal frequency on your PIC Trainer
and calculate the highest baud rate for serial data transfer.

Figure 2: Port C connection to DB 9 on the development board HP-488

Page 17 of 18
Review Questions:

1. The PIC TX and RX signals ________ (are, are not) TTL-compatible.

2. In this lab, what is the role of the MAX233 (MAX232) chip?

3. With XTAL=10 MHz, what is the maximum baud rate for the PIC18F458?

4. Show how to achieve the maximum baud rate in Question 3.

5. What is the role of TXIF and RXIF? State to which register they belong to.

6. True or false. The PIC transfers data in full-duplex.

END………..

Page 18 of 18

You might also like