Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

COMP551 – Interfacing

Fall 2021

Lab 3

Light an LED Using the MPLAB Simulator

Student: Tinkleben Kauhsikbhai Patel

Student ID: 10266303

Section: 2

NOTE: Labs are due at the start of the next lab period.

/conversion/tmp/activity_task_scratch/550304157.docx
Exercises:

1. Write a program to send the values 0xFF to 0x00, to Port B. Use the
simulator to see how Port B displays the values 0xFF to 0x00 in binary.

#include <P18F458.h>

void MSDelay(unsigned int);

void main(void)

( TRISB= 0;

while (1)

PORTB=0x55; MSDelay(250);

PORTB=0xAA; MSDelay(250);

void MSDelay(unsigned int itime)

unsigned int i; unsigned char j;

for(i=0;i<itime;i++) for(j=0;j<165;j++);

2. Write a program to read from memory, then send hex values for the ASCII
characters 1, 2, 3, 4, 5, V, W, X, Y, Z to Port B. The characters are stored in
RAM using the following command;

COMP551 – Interfacing Page 2 of 4


char ‘variable name’[]= "12345VWXYZ";

Run the program in the simulator to see how Port B displays the hex values of
each ASCII character.

#include <P18F458.h>
void main(void)

unsigned char mynum [] "012345ABCD"; //data is stored in RAM

unsigned char z
TRISB=0; //make Port B an output

PORTB=mynum[x];

while();
//stay here

forever

Run the above program on your simulator to see how Port 8 displays values 30H,
31H, 32H, 33H, 34H, 35H, 41H, 42H, 43H, and 44H (the hex values for ASCII 0, 1,

2, etc.). Notice that the last statement "while()" is needed only if we run the

program
in hardware. This is like "GOTO S" or "BRAS" in Assembly language.

3. Write a program to send values of -6 to +6 to Port B. The values are to be


stored in memory using the following command;

char ‘variable name’[] = {6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6};

Run the program in the simulator to see how Port B displays the hex values of
number.

Note: For information on “Representing Negative Numbers on a PIC”,


refer to page 18 of the lab.

COMP551 – Interfacing Page 3 of 4


4. Write a program to toggle all bits of Port B, 40,000 times. Start with 0xAA as the
output. Run the program in the simulator to verify the code.

5. Modify the program in exercise 4, to include a 200 ms delay after each time the bits
are toggled. Make the delay a function (ie. Delay1TCY(), Delay10TCYX(),
Delay100TCYx(), Delay1KTCYx(), etc.)

DROPBOX SUBMISSION

- Completed cover page (1 page).

- Program output and the source code for each modified program, in exercises 1-5 (5
pages).

Note: Label the binary and hex values on the output waveforms of exercise 2 &3.

COMP551 – Interfacing Page 4 of 4

You might also like