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
     
 

microEngineering Labs, Inc. | 1-719-520-5323 | Example Program - 7SEGMENT.pbp

PICBASIC PRO program to demonstrate 7-segment LED display. Schematic can be found at http://melabs.com/resources/articles/ledart.htm (fig 6).
' Name        : 7SEGMENT.pbp
' Compiler    : PICBASIC PRO Compiler 2.6
' Assembler   : PM or MPASM
' Target PIC  : 16F, 18F types
' Hardware    : 7-segment LED
' Oscillator  : internal or external
' Keywords    : LOOKUP
' Description : PICBASIC PRO program to demonstrate 7-segment LED display.
' Schematic can be found at http://melabs.com/resources/articles/ledart.htm
' (fig 6).
'

Segments Var  PORTB
Digits   Var  PORTA
i        Var  Byte
n        Var  Byte
Value    Var  Word

   TRISB = $80         ' Set segment pins to output
   TRISA = $f0         ' Set digit pins to output

mainloop:
   For Value = 0 To 9999
     GoSub display     ' Display the value
   Next Value
        
   GoTo mainloop       ' Do it forever

' Subroutine to send the number (0 - 9999) in Value to LEDs
display:
   For i = 0 To 3      ' Loop through 4 digits
     n = Value Dig i   ' Get digit to display
     GoSub display1    ' Display the digit
     Pause 1           ' Leave it on 1 millisecond
   Next i              ' Do next digit
   Return

' Subroutine to display one digit on LED
'  i = digit number
'  n = number to display

display1:
   Digits = $ff        ' All digits off to prevent ghosting

   ' Convert binary number in n to segments for LED
   Lookup n, [$40, $79, $24, $30, $19, $12, $02, $78, $00, $18], Segments

   ' Set digit pin i to 0 (on) and the rest of the pins to 1 (off)
   Digits = ~Dcd i
   Return

           

Download the program file.