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 - 3BUTX2.pbp

PICBASIC PRO program to demonstrate multiple BUTTON commands. Each of 3 buttons toggles an LED. Hold a button for 1 second and the LED will flicker (auto-repeat).
' Name        : 3BUTX2.pbp
' Compiler    : PICBASIC PRO Compiler 2.6
' Assembler   : PM or MPASM
' Target PIC  : 28/40-pin PIC types compatible with LAB-X2 board
' Hardware    : LAB-X2 Experimenter Board
' Oscillator  : 4MHz external crystal
' Keywords    : BUTTON, TOGGLE
' Description : PICBASIC PRO program to demonstrate multiple BUTTON
' commands. Each of 3 buttons toggles an LED. Hold a button for 1
' second and the LED will flicker (auto-repeat).
'

' Define LOADER_USED to allow use of the boot loader.
' This will not affect normal program operation.
Define LOADER_USED 1

button1 VAR PORTB.4
button2 VAR PORTB.5
button3 VAR PORTB.6

LED1 VAR PORTB.0
LED2 VAR PORTB.1
LED3 VAR PORTB.2

B1   VAR BYTE   ' Working buffer 1 for button command
B2   VAR BYTE   ' Working buffer 2 for button command
B3   VAR BYTE   ' Working buffer 3 for button command

   Clear        ' Clear buffers
   PORTB = 0    ' LEDs off

   TRISB = %11110000    ' Set portb 0-3 outputs, 4-7 inputs
   OPTION_REG.7 = 0     ' Enable PORTB pull-ups

chk1:
   Pause 25
   Button button1,0,40,5,B1,0,chk2      ' Check Button 1 (Skip to 2 if Not Pressed)
   Toggle LED1  ' Toggle LED if pressed

chk2:
   Button button2,0,40,5,B2,0,chk3      ' Check Button 2 (Skip to 3 if Not Pressed)
   Toggle LED2  ' Toggle LED if pressed

chk3:
   Button button3,0,40,5,B3,0,chk1      ' Check Button 3 (Skip to 1 if Not Pressed)
   Toggle LED3  ' Toggle LED if pressed
   GoTo chk1    ' Do it forever

   End

           

Download the program file.