|
ME Labs, Inc. 719-520-5323 |
|
|
|
ME Labs, Inc. | 1-719-520-5323 | Example Program - 7SEGMENT.pbpPICBASIC 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. |
|
Copyright 2019 ME Labs, Inc. PO Box 8250 Asheville NC 28814 (719) 520-5323 (719) 520-1867 fax email: support@melabs.com |
|