Created
October 30, 2012 16:48
-
-
Save RichardPovinelli/3981447 to your computer and use it in GitHub Desktop.
Paul's working vex usart i/o
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <OpenVex.h> | |
#include "firmware.h" | |
#include "interrupts.h" | |
void resetHeartBeat(void); | |
unsigned char usartDataReady(void); | |
int usartGetChar(char * c); | |
unsigned char c = 0; | |
void main(void) | |
{ | |
controller_init(); | |
//controller_in_autonomous_mode();// see Lib/master.c | |
controller_begin_autonomous_mode(); | |
usart_init(); | |
printf("\n\"Hello, world!\"\n\t - Rex the Vex\n\n"); | |
while (TRUE) | |
{ | |
// If there is a character to get... | |
if (usartGetChar(&c)) | |
{ | |
// we're in! | |
printf("\nif (usartGetChar(&c))"); | |
// print the character that was received | |
usart_putc(c); | |
} | |
controller_submit_data(NO_WAIT); | |
}// end while | |
}// end main | |
// this is not actually used... | |
void resetHeartBeat(void) | |
{ | |
return; | |
} | |
unsigned char usartDataReady(void) | |
{ | |
// will return 0 or 1 | |
return PIR1bits.RCIF; | |
} | |
int usartGetChar(char * c) | |
{ | |
// if data is ready, newdata will be 1 | |
unsigned char newdata = usartDataReady(); | |
// Debugging: | |
//printf("\nIN USARTGETCHAR!"); | |
if (newdata) | |
{ | |
// put the value of the register into c | |
*c = RCREG1; | |
printf("\nif: %c",(char)RCREG1); | |
//printf("\nor: %c",(char)rxbyte); | |
return 1; | |
} | |
// fail: | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment