/******************************************************************** * FileName: Variable_Manipulation.c * Processor: PIC18F4520 * Compiler: MPLAB C18 v.3.06 * * This file shows some code for variable manipulation. * * Author Date Comment *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ // Your name here /** Processor Header Files *****************************************/ #include #include /** Define Constants Here ******************************************/ #define DELAY_TIME 100 /** Configuration Bits ******************************************/ #pragma config OSC = INTIO67 #pragma config WDT = OFF #pragma config LVP = OFF #pragma config BOREN = OFF #pragma config XINST = OFF /** Global Variables *********************************************/ char char_array[] = "abc"; // Example of array syntax int num_array[] = {1, 2, 3, 4, 5}; char exampleChar; // -128 to 127 unsigned char exampleUnsignedChar; // 0 to 255 int exampleInt; // -32768 to 32767 unsigned int exampleUnsignedInt; // 0 to 65536 volatile long exampleLong; // -2147483648 to 2147483647 volatile unsigned long exampleUnsignedLong; // 0 to 4294967295 volatile float exampleFloat; // smallest 1.2E-38, largest 6.8E38 /***************************************************************** * Function: void main(void) ******************************************************************/ #pragma code void main (void) { printf (" Hello World! \n"); exampleChar = 'A'; printf ("\n exampleChar = 65\n"); printf ("decimal output: %d\n", exampleChar); printf ("hex output: 0x%x\n", exampleChar); printf ("binary output: 0b%b\n", exampleChar); printf ("char output: %c\n", exampleChar); exampleInt = 32767; printf ("\n exampleInt = 32767\n"); printf ("decimal output: %d\n", exampleInt); printf ("hex output: %#x\n", exampleInt); printf ("binary output: %#b\n", exampleInt); printf ("\nPrinting strings = %s\n",char_array); // prints the Global char array exampleLong = 1234567890; // Longs get truncated to ints when printed so no fun // Use the Variables watch window to see the result exampleUnsignedLong = 4294967295; // Use the Variables watch window to see the result exampleFloat = 0.1; // floats aren't supported in printf // Use the Variables watch window to see the result exampleChar = 13 / 4; printf ("\nexampleChar = 13/4 = %d\n",exampleChar); exampleChar = 13 % 4; printf ("\nexampleChar = 13 modulo 4 = %d\n",exampleChar); while (1) { // empty loop to keep main() from being called repeatedly } }