Need Help with RS232 protocol thx

General discussion on mikroBasic.
Post Reply
Author
Message
stackerone
Posts: 2
Joined: 17 Mar 2013 15:31

Need Help with RS232 protocol thx

#1 Post by stackerone » 05 Dec 2018 14:38

Hi all, there is a best way to read command from PC(protocol)? I post my code but i think is not optimized.

Code: Select all

if Usart_Data_Ready = 1 then
           Usart_Read_Text(txt, delim)
            if strcmp(txt,"STOP")= 0 then
             KEY_POW = 0
             MAINPOW = 0
             start_status = 0
            goto main2
           end if
          if strcmp(txt,"POW1")= 0 then
             MAINPOW = 1
             RES_MCU = 1     'RESET MCU
             start_status = 1   ' disabilito pulsante start
           end if
            if strcmp(txt,"POW0")= 0 then
             MAINPOW = 0
             RES_MCU = 1
             start_status = 0
           end if
           if strcmp(txt,"KEY1")= 0 then
             KEY_POW = 1
           end if
            if strcmp(txt,"KEY0")= 0 then
             KEY_POW = 0
           end if
......

end if


I have too much string to check then i suppose is the cause of error in communication.
PC send ADCread command, PIC compare string ADCread and make ADC read then send data back to PC
sometimes i read 0 but is not true

thanks for suggestions

User avatar
petar.suknjaja
mikroElektronika team
Posts: 683
Joined: 05 Mar 2018 09:44
Location: Belgrade

Re: Need Help with RS232 protocol thx

#2 Post by petar.suknjaja » 06 Dec 2018 10:24

Hi,
I would suggest using interrupts.
There's an example for this in the MikroE compiler, I think you'll find it helpful.
Kind regards,
Petar

Post Reply

Return to “mikroBasic General”