Professional Documents
Culture Documents
Lab 3 Submission - Program - Light An LED
Lab 3 Submission - Program - Light An LED
Fall 2021
Lab 3
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 main(void)
( TRISB= 0;
while (1)
PORTB=0x55; MSDelay(250);
PORTB=0xAA; MSDelay(250);
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;
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 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.
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.
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
- 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.