1 / 5

#include < plib.h > #include "CerebotMX7cK.h" #include "Project1.h" int main() {

#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;

gautam
Download Presentation

#include < plib.h > #include "CerebotMX7cK.h" #include "Project1.h" int main() {

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. #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

  2. 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

  3. read_buttons() intread_buttons(void) { // return (PORTReadBits(IOPORT_G, BTN1 | BTN2)); return(PORTG & (BTN1 | BTN2)); } // read_buttons

  4. 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

  5. control_leds() void control_leds(intleds) { // PORTWrite(IOPORT_G, leds); LATG=leds; } // control_leds

More Related