You are on page 1of 5

COMP551 – Interfacing

Winter 2022

Lab 2

Using MPLAB and C18 to Compile a Simple Program

Navpreet Kaur
Student:

10270950
Student ID:

Section: 2

2.2.2 Program Explanation

Explain what each line of code does in the Basic Calculations example;

#include <stdio.h>, #include <P18F458.h>

Stdio.H is a header file that has the necessary information to include the
input/output related functions in our program.
#include <P18F458.h>is a processor specific library file.

#pragma config WDT = OFF

It turns the watchdog timer off

void main (void)

specifies that the main function does not return any vlue.

int x, y, z;

Declaring the variables

x = 6;

Assigning the value to a variable x

y = 8;

Assigning the value to a variable y

z = x * y;

Defining the operation to be performed

printf("%d x %d = %d\n", x, y, z);

Exercises:

· Modify the Hello World program to use a for loop to print the phrase “Hello World,
my Fleming student number is; <insert student number>”, 10 times.
· Modify the Hello World program to use a while loop to print the phrase “Hello
World, my Fleming student number is; <insert student number>”, 15 times.
· Modify the Hello World program to use a do/while loop to print the phrase “Hello
World, my Fleming student number is; <insert student number>”, 35 times.

· Write a program to convert the temperature from degrees Celsius to degrees


Fahrenheit, ranging from -200 degrees C to +200 degrees C, in increments of 20
degrees C. The program should display the table of results in the output window
only once.

You might also like