0

I can read and write message with uart and access port and it work correctly. Now I want to turn on one of the leds on the circuit For example when i send "ON" it will turn on the led( ex:RC3) I did it but just at first of running the code after that it stop .

this part of code :

if (UART1_IsRxReady()) {
         Temp Array [Index++] = UART1_Read();
    }
    if (( Temp Array[Index - 1] == '\n') || (TempArray[Index] == '\n') || (TempArray[Index] == '\r\n')) {
        if (TempArray[0] == 'O' && TempArray[1] == 'N') {
            IO_RC3_Toggle();
            for (int i = 0; i < Index; i++) {
                printf("%c", TempArray[i]);
            } UART1_Read();}
        else if (TempArray[0] == 'O' && TempArray[1] == 'F') {
            IO_RC4_Toggle();
            for (int i = 0; i < Index; i++) {
                printf("%c", TempArray[i]);
            }
            UART1_Read();
           
           
        }  Reset_Buff();
    }
  • `'\r\n'` This is a multibyte character constant. The value is implementation defined and it is higly unlikely that it will have same value as any byte you receive via UART. – Gerhardh Feb 02 '23 at 10:30
  • `IO_RC3_Toggle` I don't know your MCU but that function name looks like it toggles the state. If you want to handle a `ON` input, I would expect some function that sets a defined state to that IO pin. – Gerhardh Feb 02 '23 at 10:32
  • Your code is generally incomplete und contains typos. What does `Reset_Buff` do? Does it reset `Index`? Please read [How-to-ask](https://stackoverflow.com/help/how-to-ask) and edit your question to provide a [MCVE](http://stackoverflow.com/mcve) – Gerhardh Feb 02 '23 at 10:34
  • Reset_Buff yes for reset the index to be read again . IO_RC3_Toggle(); to change the situation of the led . – abduallah Azizi Feb 03 '23 at 12:25
  • I solved it now i can turn on-off led by just typing which pin is represent.thanks – abduallah Azizi Mar 09 '23 at 13:03

0 Answers0