I am accepting settings for my pic via rs232 from pc, i wish to enter values from 0-999 for settings and store the 3 values as units,tens,hundreds and use these in my timer loops.
My question is how do i capture that data , my compiler doesnt allow me to use sprintf (XC8 v1.33) and im not sure how to approach this problem.
if user enters "60" then i'm in danger of entering "6" in the hundreds area of eeprom, so some intelligence in what is input is also required.
Does anyone know how to address this problem best,
you will have to send a string of 3 ascii char
ie "999" to your MCU , probably with CR (carriage return or Enter) to valide and send it
so your MCU will receive this string into a buffer
your receiving routine must put zero into the buffer if detect CR car.
ie :
Code:
char buff[16];
//if you send 999 ,buff will contain
buff[0]='9'; // or 48+9=57 decimal
buff[1]='9';
buff[2]='9';
buff[3]=0 ; // because code of CR detected
when you receive CR code , you must put a Zero value to replace CR value and terminate the string
Code:
//if you send 6 value, you will receive
buff[0]='6' // or 48+6=54
buff[1]=0
CR received so buff[1]=0 // string terlmminator
check if you have a libray like "stdlib.h" (exist in C18)
to use a function to tranform ascii string into int value.
declare an integer value:
Code:
int TimerValue;
//transform buff witch contain the string (ascii value) to an integer
Timervalue=atoi(buff);
TMR0H= Timervalue <<8;
TMR0L= Timervalue & 0x00FF;
i will write the code and see how i get on,,, its a fresh change to get an actual answer than someone posting a question about content of the post, grammar, or just plain "they havent read it very closely",