i am making a simple program for PIC 16F877 that can read characters serially (RS-232) from computer. then convert that character to integer so that i can make arithmetic modification (e.g multiply it with 5) and then echo or send it back to computer.
I am having difficulty in converting character to integer (i dont know the built in function). I am new to CCS. Please help me..........
Guest_7068 Guest
Posted: Thu Mar 06, 2008 10:58 pm
Use example Ex_Sisr.c to read characters serially into a buffer and then convert the string into a number using one of the following functions.
Code:
#include <stdlib.h>
ivalue = atoi(string) // Returns 8 bit int >> Max String Length = 3
lvalue = atol(string) // Returns 16 bit value >> Max String Length = 5
i32value = atoi32(string) // Returns 32 bit value >> Max String Length = 9
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
Posted: Fri Mar 07, 2008 9:23 am
If the character contains a binary number, just cast the byte from one type to the other. Casting is a standard C term that any C book will cover. _________________ The search for better is endless. Instead simply find very good and get the job done.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum