ME Labs, Inc.
719-520-5323
 
Home:
  Developer Resources:

Programming Clues
    Sample Programs
   
    PICBASIC PRO™
Compiler Manual
    PICBASIC™ Compiler
Manual
    Serin2/Serout2 Modes
    ASCII Character Set
    Number Conversion
    Floating Point
Routines
    PBP Debug Monitor
    Articles and Tutorials

Hardware Clues
    Parts / Vendor List
    PICPROTO™ Boards
    LAB-X1 Docs
    LAB-X2 Docs
    LAB-X20 Docs
    LAB-X3 Docs
    LAB-X4 Docs
    LAB-XUSB Docs
    LAB-XT Docs
     
 

ME Labs, Inc. | 1-719-520-5323 | Example Program - KEYXU.pbp

PICBASIC PRO program to display key number on LCD.
01' Name        : KEYXU.pbp
02' Compiler    : PICBASIC PRO Compiler 2.6
03' Assembler   : MPASM
04' Target PIC  : PIC18F4550 or similar type
05' Hardware    : LAB-XUSB Experimenter Board
06' Oscillator  : 20MHz external
07' Keywords    : DCD, LCDOUT, NCD
08' Description : PICBASIC PRO program to display key number on LCD.
09'
10 
11' Define LOADER_USED to allow use of the boot loader.
12' This will not affect normal program operation.
13Define LOADER_USED 1
14 
15' RESET_ORG can be set to move the BASIC program out of the way
16' of any boot loader running from location 0, such as the
17' Microchip USB boot loader
18'Define RESET_ORG 800h
19 
20Define OSC 48      ' Core is running at 48MHz
21 
22' Define LCD pins
23Define LCD_DREG  PORTD
24Define LCD_DBIT  4
25Define LCD_RSREG PORTE
26Define LCD_RSBIT 0
27Define LCD_EREG  PORTE
28Define LCD_EBIT  1
29 
30' Define program variables
31col Var Byte   ' Keypad column
32row Var Byte   ' Keypad row
33key Var Byte   ' Key value
34 
35   INTCON2.7 = 0        ' Enable PORTB pullups
36   ADCON1 = 15          ' Make PORTA and PORTE digital
37   Low PORTE.2          ' LCD R/W low (write)
38   Pause 100            ' Wait for LCD to start
39 
40   Lcdout $fe, 1, "Press any key"  ' Display sign on message
41 
42mainloop:
43   Gosub getkey         ' Get a key from the keypad
44   Lcdout $fe, 1, #key  ' Display ASCII key number
45   Goto mainloop        ' Do it forever
46 
47' Subroutine to get a key from keypad
48getkey:
49   Pause 50                ' Debounce
50 
51getkeyu:
52   ' Wait for all keys up
53   PORTB = 0               ' All output pins low
54   TRISB = $f0             ' Bottom 4 pins out, top 4 pins in
55   If ((PORTB >> 4) != $f) Then getkeyu ' If any keys down, loop
56   Pause 50                ' Debounce
57 
58getkeyp:
59   ' Wait for keypress
60   For col = 0 to 3           ' 4 columns in keypad
61     PORTB = 0                ' All output pins low
62     TRISB = (dcd col) ^ $ff  ' Set one column pin to output
63     Pauseus 1
64     row = PORTB >> 4         ' Read row
65     If row != $f Then gotkey ' If any keydown, exit
66   Next col
67   Goto getkeyp               ' No keys down, go look again
68 
69gotkey: ' Change row and column to key number 1 - 16
70   key = (col * 4) + (ncd (row ^ $f))
71   Return                     ' Subroutine over
72 
73   End

Download the program file.