Uart to int in mikroc

Thread Starter

varunme

Joined Sep 29, 2011
60
How can i convert char from UART to int in mikroC ?

My below code to loop the number of times according to the character send from uart, does not work, can anybody help ?


Rich (BB code):
void main(){
unsigned char txt[2];
int y,rot;
char on[10];   // char table to store received string
int intme;
trisb=0x00;
portb=0x00;
 
    UART1_Init(9600);
 
 
 
// Check if character is ready for reading and read it.
        if (UART1_Data_Ready() == 1) {
        on[0] = UART1_Read();   // read one character from uart
        on[1] = '\0';           // insert terminating zero
}
 
 
 
          for(rot=0; rot<=atoi(on );  rot++)
          {
 
                 PORTB=0b00010000; delay_ms(200);
                 PORTB=0b00001000; delay_ms(200);
 
                 }
                 }
 

BillO

Joined Nov 24, 2008
1,001
Well, for one thing, the number of braces does not match. Does this even compile?

Is UART1 intrinsic or does it require an include? Where are the fucntions defined?

As for the line 'for (rot=0; rot<=atio(on ); rot++)' ??? Where is atio() defined? Which value of on[] are you after? only 0 and 1 have been loaded.

Well, don't quite know what to say.
 

Thread Starter

varunme

Joined Sep 29, 2011
60
atoi is inbuilt function
Uart1 also inbuilt

the braces are matched and compiled, but when i copy pasted, it didnt matched
i want the dynamic values of on[] . that is whatever i sent from uart.
 

hexreader

Joined Apr 16, 2011
619
You fail to wait for a character to be received.

You check once to see if a character is ready, but at start-up, first time through, there will be no character ready.

You need to keep checking UART ready, and do not continue until a character is ready
 
Top