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

136   SERIAL  COiTMU  ICAIION$  60CKETS  U9  A  DUlo


                                   RS232  Communications  (Prograrn to receive  and displav  lnformalion
                   iiqfgtl..iiil&.Ol
                    lrcm the  coripuier)  (Cortlnued)
                     !o!l  PoRfE.2                    l,CD R/it  rine  Lot  (l'i)
                     PAUSE 500                        wait  for  LcD  to  srarlup
                     OPEION-REG.7  =  0               enable  POR1B  p!11lups

                     * E Y = 0                        iniLialize   vars
                     LASTKEY  =  0

                     I,CDOUT  gFE.  1                 iniLialize   and  clear  display


                     HSERIN 1.  T!,A:BEI,' TC1IART    ge!  a  char  fron  seriaL  Port
                     I.CDOII!  CIIAR                  send  char  !o  disPLaY

                     'I.ABEIJ.
                     GOSUB  CE'KEY                  ;   get  a  ke\@ress  if  anv
                     IF   (KEY  !=  0)  AND (X:EY I=  IJASTKEY)  TSI:N
                       IISEROUT  IKEY]              ;  send  kev  ou!  seiiat   porl
                     ETIDIF
                     LASfKEY   -  KSY               ;  save  last  key  value
                     Gorlo  LooP                    ;  do  it  all  over  asain

                     GETKIY:                        ;  subroutine   Lo  geL  a  kev  fron  ke)apad
                       K E Y = 0                    ,  preset  io  no  Kev
                       F O R C o L = 0 T O 3
                                                    ;  a1L  oulput  pins  low
                         tRrsB  =  (DcD cor)   ^  SFF ;  se!  one  colmn   Pin  to  oucput
                         Row  =  PoRtB >> 4
                         IF  ROW l=  %0000111,1 THEN  GOTKEY ;
                       NEXT  COIJ
                       BETITRN                       ;  no  key  Pressed
                      GofKEY!                        ;  change  lod  and  col  to  asclr   nunb
                                                                  \0"
                        KEY  =  (coL  *  4)  +  (NcD  {Row  ^   $F))  +   ;
                      RETURN                         ;  subroutine   over
                      EAID                           ;  end  of  Progran

                       Next, we combine the send and receive  programs to give Lrs  full  communlcatlons
                     between  the LAB-XI  and the HyperTerminai  program in the computer  (This is left to
                     you. At  this stage,  you shoulal  have no problen  with  implementing thisl howeve!  a
                     couple of hints are  Provided  )
                       TL  HyperTcrminal software  lakes  carc ofreceiving,  displaying' and sending  char-
                     acters. without need  for any futher  modification  by us.
                       The LAB-XI  software  must receive  characters  from the terminal  program and dls-
                     play them on the LCD.  lt  also has to read the keyboard and send  what it sees  to lhe
                     tcrminal. The receiving and sending  m  st be in the same  main loop'
   140   141   142   143   144   145   146   147   148   149   150