Page 141 - Making PIC Microcontroller Instruments and Controllers
P. 141

132   sERllL  coMMuNlcATlOrlS: SOCKETS U9 AllD Ul0



                                                                             with
                                                        (Program
                   l::Ptdiiallig-ili:  Rs232 Communications     lo communicale a computed
                     lcontinued)
                     RETI'RN                           qo  back  Lo  calLer
                                                       subroutine   to  send  a  character
                     CHAROu!:                          to  usarl  Lransnilter
                     IF  PIR1.1T  =  O  THEAI CITAROu!  wait  for  transnit   registe!   enpty
                       TXREG  =  Bl                    send  characLer  io  transnit

                     REAURN                            go  back  to  caLLer
                     EIID

                                      jfyou
                                                                    of
                      On the other hand,   need a  greatcr  understanding what  is going  on, read on
                      TheLAB-XIlelsus experiment  with twotypes  ofserial co  munications  The board
                    comes  with hardware for the  RS232 standard on board  and an emply socket  that can be
                    coniigured  with the RS485  protocol (a  line driver lC musl be  ndded). Only one  type of
                                  can be actve at any one  time, andlhcchip  ihatis not being used  must
                    communications
                    be removed  from the board. The RS232  communicalions are  routed to the DB 9  female
                    conneclor on the  boa]d,.md there are  PC boa]d holes fot s.  three'pin connector  at Jl0
                                           The IC rcquired by  the RS485 is the SN175176A  or equiv-
                    &rRS,l85  communications.
                    alent line driver.
                      The two staDdards are simil  and, simply stated,  using RS485 allows  you io go
                    longer distances  and the communicaiion  is more noise  tolerart.  (This  is related io the
                    capacitance of the lines used and slronger  drivers being employed.  The discussion  of
                    the why and  how ofthis is beyond the  scope of this book.)
                      The compiler suppots communications  to both standards and  the specified compiier
                    conmrmds should be used whenever  possjble.  Writing your own sequences  lbr control-
                                                             even though it might  be inslructive
                    ling serial communications  is couDterproductive,
                                                                          and the  hardware  you
                    The compiier  uses the same commands  to access both standards,
                    put  in place  determines how the signaLs  are senl o!r! and  received.  (Take  a  minute to look
                    at Figures 8-  l and  8-2 to see what the complications ar.J.)
                      Coimunications  arc timed according to the speciiication of the oscillator  For the
                    proper  timing to be achieved,  the OSC command  has to be sct to the actual oscillator
                    frequency in use. Ifthe ffequercies are not matched,  conmunications  will be sped up
                    or slowed  down  (in  spced) based  on the extent ofthe  mismatch.Ilyou are  actudly using
                                                                                    will slot!
                    a 4 M Hz osci  llator and specify OSC  20 in  your program, ihe communications
                    down to onlr  fifth thespecified spccd because  the system is actuallyrunning  at one-fifth
                    the 20 MHz speed.
                      In order to experiment  with colnmunications,  we need to bc able  to communicate  with
                    an  externaldevice. The easiestdevice use is apersonal  computcr set  up with a dumb
                                                    to
                    terminal  program. The various versions of  Microsoft Office Works software  all contaln
                    a tefminal  program  that  you  can access and use.
                      Adumb terminal may be set  up by following these  instructions:

                      Co to the  St?u]t menu in your  PC command lrough, then  select
   136   137   138   139   140   141   142   143   144   145   146