Uart to int in mikroc

Discussion in 'Embedded Systems and Microcontrollers' started by varunme, Mar 21, 2012.

  1. varunme

    Thread Starter Active Member

    Sep 29, 2011
    60
    0
    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 ?


    Code ( (Unknown Language)):
    1.  
    2.  
    3.  
    4. void main(){
    5. unsigned char txt[2];
    6. int y,rot;
    7. char on[10];   // char table to store received string
    8. int intme;
    9. trisb=0x00;
    10. portb=0x00;
    11.  
    12.     UART1_Init(9600);
    13.  
    14.  
    15.  
    16. // Check if character is ready for reading and read it.
    17.         if (UART1_Data_Ready() == 1) {
    18.         on[0] = UART1_Read();   // read one character from uart
    19.         on[1] = '\0';           // insert terminating zero
    20. }
    21.  
    22.  
    23.  
    24.           for(rot=0; rot<=atoi(on );  rot++)
    25.           {
    26.  
    27.                  PORTB=0b00010000; delay_ms(200);
    28.                  PORTB=0b00001000; delay_ms(200);
    29.  
    30.                  }
    31.                  }
    32.  
    33.  
     
  2. BillO

    Distinguished Member

    Nov 24, 2008
    993
    137
    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.
     
  3. varunme

    Thread Starter Active Member

    Sep 29, 2011
    60
    0
    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.
     
  4. hexreader

    Active Member

    Apr 16, 2011
    280
    111
    Which PIC are you using?
     
  5. hexreader

    Active Member

    Apr 16, 2011
    280
    111
    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
     
    varunme likes this.
  6. varunme

    Thread Starter Active Member

    Sep 29, 2011
    60
    0
    i am using 16f877a
     
  7. varunme

    Thread Starter Active Member

    Sep 29, 2011
    60
    0
    yes, i made it loop onetime,

    but how can i make it continous loop ?
     
  8. varunme

    Thread Starter Active Member

    Sep 29, 2011
    60
    0
    ohh , yes , its working now
     
Loading...