Electronics > Microcontrollers
XC8 Soft UART on PIC16F819-Help please
djsb:
How would I convert the output from the ADC on the PIC16F819 from an integer into ASCII format for sending to the serial port? There is no itoa function and I don't know how to use sprintf. What is the most efficient way to send an ADC reading that's been converted to a voltage reading. The resources on the PIC16F819 are very limited. Thanks.
DavidAlfa:
Make your own itoa?
Given it's 10 or 12bit max, you can simply it by a lot.
5 minute example:
https://onlinegdb.com/dNvOImm1D
--- Code: ---char * _itoa (uint16_t n, uint8_t pad, char * str) {
const uint16_t val[4] = { 1000, 100, 10, 1 };
uint8_t first=0;
char *s = str;
for(uint8_t i=0; i<4; i++){
uint8_t cnt = 0;
uint16_t cmp = val[i];
while(n >= cmp){
cnt++;
n -= cmp;
}
if(cnt || first || i==3 || pad>=(4-i)){
*s++ = cnt + 48;
first = 1;
}
}
*s = '\0';
return str;
}
--- End code ---
Ground_Loop:
ITOA() should be in the stdlib.h library.
DavidAlfa:
Indeed:
http://www.gtronic.it/test/wp-content/uploads/2017/01/XC8-compiler.pdf#page=258
Navigation
[0] Message Index
[*] Previous page
Go to full version