Searching \ for 'Serial waitfor with CCS C' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/io/serials.htm?key=serial
Search entire site for: 'Serial waitfor with CCS C'.

Truncated match.
PICList Thread
'Serial waitfor with CCS C'
1997\01\05@185412 by MSI: Sean Cunningham

flavicon
face
Can anyone show code examples for CCS C for how to implement a waitfor
serial routine, as in the following PBASIC Code:

serin 2,N9600,("aba"),w5,w6,w7

[waits for the characters "aba" and then retrieves the next 3
characters].

1997\01\06@065035 by Chaipi Wijnbergen

flavicon
picon face
On Sun, 5 Jan 1997, MSI: Sean Cunningham wrote:

> Can anyone show code examples for CCS C for how to implement a waitfor
> serial routine, as in the following PBASIC Code:
>
> serin 2,N9600,("aba"),w5,w6,w7
>
> [waits for the characters "aba" and then retrieves the next 3
> characters].


How about something like :


#use Delay (Clock=4000000)
#use RS232(Baud=9600, Xmit=PIN_B7, Rcv=PIN_B6)
#include <stdio.h>


main ()
{
   byte ucState = _DidNotRecieveAnythingYet;
   /*-------------------------------------------------------------------*\
   | Loop forever                                                        |
   \*-------------------------------------------------------------------*/
   do
     {
      /*----------------------------------------------------------------*\
      | Check If need communication                                      |
      \*----------------------------------------------------------------*/
      if (kbhit())
         {
          /*------------------------------------------------------------*\
          | Get a character                                              |
          \*------------------------------------------------------------*/
          ucSerialInput1 = getc();
          switch (ucState)
            {
             case _DidNotRecieveAnythingYet:
                  if (ucSerialInput1 == 'a')
                      ucState = _RecieveFirstA;
             break;
             case _RecievedFirstA:
                  if (ucSerialInput1 == 'b')
                      ucState = _RecieveB;
                  else
                      ucState = _DidNotRecieveAnythingYet;
             break;
             case _RecievedB:
                  if (ucSerialInput1 == 'a')
                     {
                      w5 = getc();
                      w6 = getc();
                      w7 = getc();
                      ... do something ...
                      ucState = _DidNotRecieveAnythingYet;
                     }
             break;
         }
    }
}


Chaipi

                              \\\|///
                            \\  ~ ~  //
                             (  @ @  )
----------------------------oOOo-(_)-oOOo--------------------------------------
!                                                                             !
! Chaipi Wijnbergen                                                           !
! Electronics/Computer Eng. M.Sc.  Tel    : +972-8-9343079                    !
! Optical Imaging Laboratory       Fax    : +972-8-9344129                    !
! Brain Research Center            Email  : spam_OUTchaipiTakeThisOuTspamtohu0.weizmann.ac.il       !
! Weizmann Institute of Science    URL    : http://www.weizmann.ac.il/~chaipi !
! Rehovot 76100 ISRAEL             IPhone : chaipi                            !
!                                                                             !
------------------------------------Oooo.--------------------------------------
                         .oooO     (   )
                         (   )      ) /
                          \ (      (_/
                           \_)

More... (looser matching)
- Last day of these posts
- In 1997 , 1998 only
- Today
- New search...