ELE2303 WORKSHOP 1 – C PROGRAMMING BASICS, MPLABX AND XC8
Demo section
How to run MPLABX, set up a project, compile and use the built-in simulator
Problem section
1. Create your own project for a PIC18F452 processor
Include a main program with an endless loop
Declare a variable i and increment it each loop
2. Declare variables of types char, unsigned int, long and float
Write lines of code that initialise values for the variables
Write lines of code that assign values to the variables
Write lines of code that do some basic mathematics +, -, *, /
Try assigning the value of one variable type to another
Try a range of different combinations of variables
(Test the code above using the built-in simulator)
3. Create a loop within your main program’s endless loop which counts to 10
Include an IF statement so when the count reaches 5 it skips counting 6
Try a range of different tests
Homework section
Create a new project, for the PIC18F4620 processor.
Select the built-in Simulator (for debugging)
Write and test a program which:
Declares any variables you require
Initialises all variables before running into an endless loop
Calculate the product of the series of values 1.1, 2.2, 3.3 up to and
including 9.9, but skip 6.6 on the way, (i.e. do not divide by 6.6 at the end)
Note that testing for exact values of floating point numbers can be
problematic
Store the resulting number in a variable named result
Then count down from the number in result to zero in steps of 10
Count or calculate how many times 10 can be taken from result before it
reaches zero
Store the answer in a variable named timesELE2303 WORKSHOP 1 – C PROGRAMMING BASICS, MPLABX AND XC8
Demo section
How to run MPLABX, set up a project, compile and use the built-in simulator
Problem section
1. Create your own project for a PIC18F452 processor
Include a main program with an endless loop
Declare a variable i and increment it each loop
2. Declare variables of types char, unsigned int, long and float
Write lines of code that initialise values for the variables
Write lines of code that assign values to the variables
Write lines of code that do some basic mathematics +, -, *, /
Try assigning the value of one variable type to another
Try a range of different combinations of variables
(Test the code above using the built-in simulator)
3. Create a loop within your main program’s endless loop which counts to 10
Include an IF statement so when the count reaches 5 it skips counting 6
Try a range of different tests
Homework section
Create a new project, for the PIC18F4620 processor.
Select the built-in Simulator (for debugging)
Write and test a program which:
Declares any variables you require
Initialises all variables before running into an endless loop
Calculate the product of the series of values 1.1, 2.2, 3.3 up to and
including 9.9, but skip 6.6 on the way, (i.e. do not divide by 6.6 at the end)
Note that testing for exact values of floating point numbers can be
problematic
Store the resulting number in a variable named result
Then count down from the number in result to zero in steps of 10
Count or calculate how many times 10 can be taken from result before it
reaches zero
Store the answer in a variable named times