S215  090803

Homework IH03-24
Explanation of IG31-20 Adding Two Numbers Program
OEES 215

Back to Main Page
   
//******************************************************************************
// IG31-20 Adding Two Numbers                                    S215  09 0731
// *****************************************************************************
#include "s215-header8.h"

#pragma code
void main (void)
{
unsigned char x, y, z;    /* This is a variable-declaration statement.
- x, y, and z are variables, which means we can put different numbers into
them on the fly.
- We need to use such declaration statements to tell the compiler how much memory
space is needed for each variable. We are also telling it how to treat operations
on the variables.
- The compiler is a piece of software that takes our programs written in the C
language and converts them into machine language--the language that the PIC
understands. (Machine language consists of only binary numbers--not very user
friendly.)
- The word "unsigned" above means that these variables will not be containing
any negative numbers. This means that we do not need to give up one of the bits in
each variable to tell whether the number is positive or negative.
- The word "char" above stands for "character." A character is one letter, one
numerical digit, or one special symbol (such as $). For example, the following
are characters: a, b, z, 0, 1, 2, #, @. In computers there is a code used to
represent characters (the ASCII code, or one similar to it). One byte (8 bits) is
used to represent each character.
- In the C programming language, there is no "byte" variable type. Instead, we use
the "char" variable type when we need only one byte for storing numbers contained
in the variables. A little strange, but that's the way it is.
- All in all, the line "unsigned char x, y, z;" tells the compiler that the
variables x, y, and z will only be containing positive numbers. It also tells the
compiler to reserve one byte for each variable. One byte can contain numbers
between 0 and 255 (binary 00000000 to 11111111). */

InitPorts();
//----------------------------------
while (1==1)
{
//|||||||||||||||||||||||||| Main Loop ||||||||||||||||||||||||||||||||
x = ADC8msb();            //Get a number between 0 and 255 that represents the
                        //  pot's position.
y = SWITCHES;            //Get a number from the switches. (By turning each of the
                        //  8 switches either on or off, you can represent a binary
                        //  number between 0 and 255.
z = x + y;                //Add together the numbers contained in x and y and put
                        //  the sum into z.
DispN(z, 3, 0);            //Display the contents of z in the alphanumeric display,
                        //  using 3 digit positions starting at position 0 and ending
                        //  at digit position 2. In other words, display digits in
                        //  digit positions 0, 1, and 2.

//|||||||||||||||||||||||| End of Main Loop ||||||||||||||||||||||||||       
}
}

Back to Main Page