Here is the code that I have. I am unable to test it right now, so I’m just wondering if someone can verify that this will take the full str string and send each character individually to TXREG
char str [10];
int n;
n = sprintf(str, "%u%% %u\n", Duty_Cycle, DAC_Output);
transmit_uart(str); // Send the value
And here is the transmit_uart() method.
void transmit_uart(const char *value) {
for(int i = 0; value[i] != '\0'; i++) {
while(TXIF == 0) {}
TXREG = value[i];
}
}
So this should send something like
50% 128
Every time I call transmit_uart() with a string formatted the way I have it up there.
UPDATE: I was able to test it yesterday, and this did in fact work! Thanks for all the help!
Although I haven’t personally loaded it onto an MCU and tested it, yes, that looks fine as long as
TXIFdoes what it looks like.You really should use
snprintfor a larger buffer. This is one case where overflowing the integer (as in simply having too large a value, or any negative value) would cascade into buffer overflow.