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

7'   COX'ROIL|XG THE OUIDUI AIID READII{G THE IIIPI'T



                                                         the keyboard rows and  columns)
                   lilBi!iii?!i:gil4::l  Read keyboard  (Reading
                    (Continuect)
                    l,OW PORTE.2                 ;  LCD  R/ll  low   (!vrite)
                    PAUSE  500                   ;  waiL   for   LCD  !o  starL   uP

                    RIIADING  VAR  BYTE          ;  define  the  variabLes
                    A',PEA  \ITR  BYTE
                    BI'FFER  1IAR  BYTE
                                                 ;  seL  up  port  B  pu1l  ups
                    OPEION-REC,  ?  =  O         ;  enabLe PORTB  prrlL  ups  to  nake  B4-B7 high
                    IRISB  =  %11110000          ;  nake  B7  B4  inputs,   B3  B0  outputs
                    BUFFER=%11111111             ;  no  key  has  been  pressed  fot  disPLaY
                                                 ;  ser  up  the  inilial   LcD  readinqs
                    tcDoun  $FE,  1              ;  clear  the  LCD
                    ICDOUT  $FE,  9C0,   'ROW='.BIN4   {EUTFER  &  SoF),"  CO!=",
                    BIN4  BUFFER >>4

                    looP:
                      PORTB  -%OOOO1I1O          ;  set  line  BQ Lot  so  we  can  read  xow 1
                      FoR  ar,PEA  =  1  to  4   ;  only  need  !o  look  at  4  rows
                        LCDOtM $FE,   g8O,  BIIIS  POBEB,'  SCAIIVIEW  Ez  ;  see  bits   scanned
                        rF  (POREB  &  sFO)$FO  fEEN                 one  of  lhe  bias  in  84
                                                        ;  to  87  changes  we  imediaLely
                                                        ;  have  !o  store  Lhe value  of  PoRTB
                          BUFFER  =PoRTB                ;  in  a  safe  Place.
                          GOSUB SIIOI'IKEYPRESS
                        EIJSE
                        ENDTF
                          PAUSE 50                      ;  pause  lets  us  see  the  scan  but
                                                        ;  iL  also  neans  hold  a  keY  down
                                                        ;  for  over  50  usecs  Lo  hawe  at
                                                        ;  register.   Pause be  renowed
                                                        ;  after  You  hawe  seen  Lhe  bits
                                                        ;  scaming   on  the  LcD
                          FORIB=  PORTB  <<1            ;  nove  bits  left  one  place  for  nert
                                                        ;  line  1ow
                          PORTB=  PORTB  +  1           ;  put  1 back  in  LSBit,  the  righ!  biL
                       NE'<T AI.PHA
                     GOTO t OOP

                     SHOWKEYPRESS
                                   !
                                    gco,  \Ro!'r=Z,
                       r,cDott!  saE,              BrN4   {BUFFER  &  soF),-
                     \   cor,=z,  BtN4   BUFFER >>4
                     RETURN
                     END
   77   78   79   80   81   82   83   84   85   86   87