Lab Manual CSE332 Embedded Systems and M
Lab Manual CSE332 Embedded Systems and M
Lab Manual
CSE332
Prepared By
Salma Hamoda
OBJECTIVES:
REFERENCE:
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______.
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:
MATERIALS:
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?
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:
REFERENCES:
MATERIALS:
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.
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 = ___.
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?
Demonstrate the lab working to the professor by running the program (the
LCD name).
Page 7 of 18
Page 8 of 18
Page 9 of 18
Lab 4
PIC Timer Programming
OBJECTIVES:
REFERENCE:
MATERIALS:
ACTIVITY 1:
ACTIVITY 2:
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:
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.
Page 11 of 18
Lab 5
Interrupt Programming
OBJECTIVES:
REFERENCE:
MATERIALS:
Pre Lab: Show to the instructor the answer to following Prelab questions
before you start the lab experiment.
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:
Page 12 of 18
ACTIVITY 3:
Review Questions:
1. For the PIC18F458/4580, name all the interrupts associated with timers and
ADC.
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:
Review Questions:
(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?
Page 15 of 18
Lab 7
PIC Serial Port Programming
OBJECTIVES:
REFERENCE:
MATERIALS:
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.
Page 17 of 18
Review Questions:
3. With XTAL=10 MHz, what is the maximum baud rate for the PIC18F458?
5. What is the role of TXIF and RXIF? State to which register they belong to.
END………..
Page 18 of 18