/* * debug_demo.c * * Created on: Jan 24, 2021 * Author: johnsontimoj */ #include #include "msp.h" int fn1(float val); void fn2(int * rslt); int main(void){ int x; int y; char aa; char bb; float one; float two; // basic variable watching x = 3; y = 4; aa = 'f'; bb = 'g'; one = 0.55; two = 2.222; // function call with void return printf("%i %i\n", x, y); // function call with return x = fn1(one); // function call with pointer fn2(&y); // scan for input printf("Please enter an int, a float, and a character: \n"); scanf("%i %f %c", &x, &one, &aa); // for loop int i; for(i = 0; i < y; i++) x = x + 1; // Hardware setup // Note: pin 5 is Port 4 bit 1 P4->DIR = P4->DIR | 0x02; // Output P4->OUT = P4->OUT & ~0x02; // Default to low // Create squarewave (0.5Hz) i = 3; while(i > 0){ __delay_cycles(3000000); P4->OUT = P4->OUT | 0x02; // high __delay_cycles(3000000); P4->OUT = P4->OUT & ~0x02; // low i--; } // end while // Hardware setup // Using p1.7 as input P1->DIR = P1->DIR & ~0x80; // continuous read for input i = 0; while(i < 10){ x = P1->IN & 0x80; y = (P1->IN & 0x80) && 0x01; __delay_cycles(3000000); i++; }// end while return 0; } int fn1(float val){ if(val > 1) return 3; else if(val > 0) return 4; else return 5; }// end fn1 void fn2(int * rslt){ switch(*rslt){ case 0: *rslt = 1; break; case 1: *rslt = 2; break; default: *rslt = *rslt * *rslt; break; }// end switch }// end fn2