ELE2303 WORKSHOP 3 – functions, delays and port IO
Demo section
How to setup PICSimLab on MPLABX, set up a project, compile and test on PICSimLab
Problem section
1. Create your own project for a PIC18F4620 processor
Define the crystal frequency to 10 MHz for the delay #define _XTAL_FREQ
10000000
Set the TRISD register for PORTD as outputs
Include a main program with an endless loop
Toggle the value on LATD to make the LEDS change once per second
Use a loop to create a 1 second delay from 100x 10ms delays __delay_ms(10);
Test on the PICSimLab simulator
Set the speed of the simulator to 10 MHz
2. Create a subroutine which achieves a one second delay
Call that from the main program instead of the inline delay you had before
3. Break the program into two files – the main and the delay routine
Create a header file the provides the function prototype
Use a #include in the main program
4. Alter the program to pass a parameter to your delay routine where the parameter
is the number of seconds to delay.
5. Create a function that reads the state of buttons on PORTB bits 0 to 4
returning an integer value 1 for RB0, 2, for RB1, 3 for RB3 and 4 for RB4.
write that return value to PORTD so it can be seen on the LEDS.
Homework section
Create a new project, for the PIC18F4620 processor.
Select the PICSimLab Simulator (for debugging)
Complete all the parts of the workshop above..