Jon Wilder
Active Member
I'm creating a template for Arduino-like behavior in XC8. Working on the interrupt implementation as we speak, but this is what I have thus far -
PIC-Duino C source file -
PIC-Duino C header file -
Really simple to use. In the Source Files virtual directory in your MPLAB X project, create your main source file, main.c. Additionally, load the source file pic-duino.c into your Source Files virtual directory. Optionally, load the header file pic-duino.h into the Header Files virtual directory. Lastly, in main.c, include the header file pic-duino.h, then define two void functions void of any parameters, named 'setup' and 'loop' just like an Arduino sketch -
PIC-Duino C source file -
C:
/* pic-duino.c */
#include <xc.h>
#include "pic-template.h"
void main() {
/* The main wrapper, where all the magic happens */
setup();
while(1) {
loop();
}
}
/* End of file */
PIC-Duino C header file -
C:
/* pic-duino.h */
/**
* A wrapper for setup code that only runs once. Will be user defined in main.c.
*/
void setup(void);
/**
* A wrapper for user defined main loop that runs forever. Will be user defined in main.c.
*/
void loop(void);
/* End of file */
Really simple to use. In the Source Files virtual directory in your MPLAB X project, create your main source file, main.c. Additionally, load the source file pic-duino.c into your Source Files virtual directory. Optionally, load the header file pic-duino.h into the Header Files virtual directory. Lastly, in main.c, include the header file pic-duino.h, then define two void functions void of any parameters, named 'setup' and 'loop' just like an Arduino sketch -
C:
#include <xc.h>
#include "pic-duino.h"
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
/* End of file */