Page 273 - Amphibionics : Build Your Own Biologically Inspired Robot
P. 273

Amphibionics 06  3/24/03  9:02 AM  Page 252
                                                       Amphibionics
                                          When using the serin command to receive data, PicBasic Pro lets
                                          you define a qualifier enclosed within brackets before any more
                                          data  is  received.  Serin must  receive  these  bytes  in  exact  order
                                          before receiving any data items. If any bytes received do not match
                                          the next byte in the qualifier sequence, the qualification process
                                          starts over (i.e., the next received byte is compared to the first item
                                          in the qualifier list). This makes it easy for us to program an iden-
                                          tification code for each device or robot that we are going to con-
                                          trol. It also ensures that good data are being sent, and cuts down
                                          on erroneous interpretation of the received serial data. Once the
                                          qualifiers are satisfied, serin begins storing data in the variables
                                          associated with each item. If the variable name is used alone, the
                                          value of the received ASCII character is stored in the variable.

                                          For our test program, we will use the qualifier “Z” to identify that
                                          the received data is coming from our transmitter. Once the char-
                                          acter “Z” has been received, the next byte of information will be
                                          stored in a variable. We can then compare this information to cer-
                                          tain control commands and carry out the tasks associated to them.
                                          The line of code that will receive the serial data looks like this:

                                          serin rxmit,rx_baud,["Z"],control

                                          The serial data is received on pin rxmit (PORTB.0) at a baud rate
                                          of rx_baud (2400). The program execution will remain in a tight
                                          loop, receiving serial data and comparing each received byte to the
                                          character “Z.” When the character “Z” is received, the next data
                                          byte is stored in the variable named control. We will then compare
                                          the  contents  of  the  variable  control to  the  character  “A.”  If  the
                                          comparison is true, then the microcontroller will produce a couple
                                          of  tones  on  the  piezo  speaker.  The  receiver  program  is  called
                                          receive-test.bas and  is  listed  in  Program  6.7.  Program  the  PIC
                                          16F84 with the receive-test.hex file listed in Program 6.8. Place
                                          the PIC in the 18-pin socket on the robot’s main board.


                      252
   268   269   270   271   272   273   274   275   276   277   278