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

sEtt[{G oul ouR  DEslGt{ ll{lEt{t   153


                                                        to simulate back  pack
                  :::P.fi0iittllgitl:tl  For a PIC  15F84A  (Prosram
                   lby  rnicroEngineering Labsl)
                   ;  PicBasic   Pro  program  to  sinulate   an  LCD  Backpack
                   ;  Define  LcD  registers   and  bits
                   DEFIIiIE  LCD-DREG  PORfD
                   DEFIIIE   IJCD  DBIT   4    j
                   DEFINE  IJCD  RSREG  PORTE   ;
                   DEFINE  LCD_RSBIT  O        ;
                   DEFINE   I,CD  EREG  PORTE
                   DEFINE   I.CD_EBIT   1      ;
                   CI|AR  VlrR  BYTE           ;  Storaqe   for   serial   cha.acter
                   MODE vaR  BYTE              ;  Storage   for   seriaL   node
                   Rcv  vAR  PoRl[B.?          ;  sexia]   receive   Pin
                   BAUD VAR  PORTA.o           r  Barrd  raLe  pin   0  =  2400,  1  =  9600
                   STATE  vAR  POR!A,1         ;  InverLed   or  lrue   serial   data   1  =  true

                   a.DcoNl  =  %00000111       ,  set   PoRTA  and  PoRTE  to  digital
                   l,Olf  PORTE.2              ,  l,CD  R/w  line   1ow  (i'l)
                   PAUSE  500                  ;  i/ait   for   LCD  to  slarLup

                   MODE  =  0                  ;  Set  node
                   IF   (BAUD  ==  t)   TEEN
                     MoDE  =  2                ;  set  baud  rate
                   ENDIF

                   IF   (STATE  ==  0)  IHEN
                     MODE  =  MODE  +  4       ;  Set  invelled   or  true
                   ENDIF

                   r,cDout  $FE,  L            i  Initialize   and  clear   displav

                   LOOP,
                     SERIN  RC{/,  MODE,  CEAR  ;  Get  a  char   fron   serial   input
                     LCDOUT  CEAR              ;  Send  char   to  display
                   GOIO  IOOP                  ,  Do  rt  all   over  again
                   END                         ;  end  Progran

                    This  program  is for the 16F8,1A, but it can be  used on the 16F877Awith  appropriate
                  DEFINES. You  have  settheseDEFINES  many times  before now, so lhis should  not be
                  a  problem.
                    The  preceding  proFam  is for a 16F84A PIC. tf you  load this  pro$am into the  PIC,
                  you  can connect the 16F84A  to the LCD, dnd any serial  information that comes  in on
                  PORTB.T willbe displayed on  the LCD. Now  you  can conlrol  the LCD from one  line
                  on the main  processor  (The  selected  pin does nol have to be  PORTB.7. Any tree  pin
                  can be specified  as the input data  pin  in the  pfogram.)
                    The wiring  diagram for the 16F84A  is shown  in Figure 9.2.
   156   157   158   159   160   161   162   163   164   165   166