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.

This study source was downloaded by 100000853623340 from CourseHero.com on 09-28-2022 22:29:57 GMT -05:00

https://www.coursehero.com/file/132026063/hello-world-2rtf/
#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:

·0 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.

This study source was downloaded by 100000853623340 from CourseHero.com on 09-28-2022 22:29:57 GMT -05:00

https://www.coursehero.com/file/132026063/hello-world-2rtf/
·1 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.

This study source was downloaded by 100000853623340 from CourseHero.com on 09-28-2022 22:29:57 GMT -05:00

https://www.coursehero.com/file/132026063/hello-world-2rtf/
·2 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.

This study source was downloaded by 100000853623340 from CourseHero.com on 09-28-2022 22:29:57 GMT -05:00

https://www.coursehero.com/file/132026063/hello-world-2rtf/
·3 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.

This study source was downloaded by 100000853623340 from CourseHero.com on 09-28-2022 22:29:57 GMT -05:00

https://www.coursehero.com/file/132026063/hello-world-2rtf/
Powered by TCPDF (www.tcpdf.org)

You might also like