50 likes | 280 Views
#include < plib.h > #include "CerebotMX7cK.h" #include "Project1.h" int main() { unsigned int buttons, leds ; initialize_system (); while(1) { buttons= read_buttons (); leds = decode_buttons (buttons); control_leds ( leds ); } // while(1) return 1;
E N D
#include <plib.h> #include "CerebotMX7cK.h" #include "Project1.h" int main() { unsigned int buttons, leds; initialize_system(); while(1) { buttons=read_buttons(); leds=decode_buttons(buttons); control_leds(leds); } // while(1) return 1; } // main
What to include!?!?! • Header files have definitions and function prototypes • Include the header file if you want to use a definition or function from the file • Never include .c files!!! • Never include config_bits.h (it is included by CerebotMX7ck.c) • Don’t change CerebotMX7ck .h or .c files • Instead, create your own project[#].h file • Include CerebotMX7ch.h and plib.h in your project[#].c file
read_buttons() intread_buttons(void) { // return (PORTReadBits(IOPORT_G, BTN1 | BTN2)); return(PORTG & (BTN1 | BTN2)); } // read_buttons
decode_buttons() intdecode_buttons(int buttons) { unsigned intleds=0; // could of intializedto LED1 switch (buttons) { case BTN1 : leds=LED2; break; case BTN2: leds=LED3; break; case BTN1 | BTN2 : leds=LED4; break; default : // no buttons leds=LED1; break; } // case return(leds); } // decode_buttons
control_leds() void control_leds(intleds) { // PORTWrite(IOPORT_G, leds); LATG=leds; } // control_leds