onemilimeter
Member level 3
Demo version of PICBASIC PRO is not fully functional. What are the limitations? Thanks.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'****************************************************************
'* Name : SLED4_2.BAS *
'* Author : Bruce Reynolds *
'* Notice : Copyright (c) 2004 Reynolds Electronics *
'* : All Rights Reserved *
'* Date : 7/02/2004 *
'* Version : 1.0 *
'* Notes : Test routines for the SLED4 4-digit serial *
'* : LED display module *
'****************************************************************
' PIC16F876A @ 20MHz w/boot-loader
DEFINE OSC 20
DEFINE LOADER_USED 1
INCLUDE "modedefs.bas"
EN VAR PORTB.5 ' Enable pin
CLK VAR PORTB.6 ' Clock pin
DOUT VAR PORTB.7 ' Data out pin
X VAR WORD ' GP var
Y VAR BYTE ' GP var
' Bank #1 controls the colon ":"
D2 VAR BYTE ' Bank #2 right LED digit
D3 VAR BYTE ' Bank #3
D4 VAR BYTE ' Bank #4
D5 VAR BYTE ' Bank #5 left LED digit
CFG VAR BYTE ' Holds display bank/digit config value
TRISB = 0
Main:
GoSub Counter2 ' Count from 0 to 1000
GoSub LampTest ' Lamp test with 8.8.:8.8. + blinking
GoSub Clock ' 4-digit clock from 16:50 to 17:00 w/blinking colon
GoSub Counter0 ' Colon ON + 100% bright, count on right 2, then 50% on left 2
GoSub Help ' Display H.E.L.P. pulsing brightness from 50% to 100%
GoSub Counter1 ' Counte from 9994 to 0000 @ 50% brightness
GoSub Ouch ' Display OUCH pulsing brightness from 50% to 100%
GoTo Main
Counter0: ' Count 00-14h on right 100% bright, then count on left with 50% bright
CFG = %11110001 ' Digits 5,4 special decode/OFF, 3,2,1 HEX decode
GoSub Config ' Configure display
' Now write data to the display
For X = 0 TO 20 ' Count from 0 to 14h on digits 3 & 2 with leading 0 blanking
EN = 0 ' Display banks 5 4 3\2 :=ON
ShiftOut DOUT, CLK, MSBFIRST, [%1000\4, $0\4, $0\4, X, $2\4]
EN = 1 ' Transfer data into display registers
Pause 150 ' Pause 150mS
Next X
CFG = %11001101 ' Digits 5,4,1 HEX decode, 3,2 special/OFF
GoSub Config ' Configure display
For X = 0 TO 20 ' Count from 0 to 14h on digits 5 & 4 with leading 0 blanking
EN = 0 ' Enable data input 5\4 3 2 :=ON
ShiftOut DOUT, CLK, MSBFIRST, [%0000\4, X, $0\4, $0\4, $2\4]
EN = 1 ' Transfer data into display registers
Pause 150 ' Display count from 0 to 14h
Next X
Pause 500
Return
Counter1: ' Count from 9994 to 0000
CFG = %11000011 ' Digits 5,4,3,2 HEX decode, 1 special decode
GoSub Config ' Configure display
' Now write data to the display
D5=9 : D4=9 : D3=9 : D2=4 ' Load counter with 9994 on start
For X = 0 TO 6 ' Count from 9994 to 0000
EN = 0 ' Enable data input
IF D2 > 9 Then D2=0 : D3=D3+1 ' Increment each higher digit # on 9
IF D3 > 9 Then D3=0 : D4=D4+1 ' value of each lower digit # for BCD
IF D4 > 9 Then D4=0 : D5=D5+1 ' counting
IF D5 > 9 Then D5=0 ' bright 5 4 3 2 :=OFF
ShiftOut DOUT, CLK, MSBFIRST, [%0000\4, D5\4, D4\4, D3\4, D2\4, $0\4]
EN = 1 ' Transfer data into display registers
Pause 500 ' Without pause, display can count from 0 to 9999 in ~6 seconds
D2=D2+1 ' Increment counter
Next X
Pause 500
Return
Counter2: ' Count from 0 to 1000
CFG = %11000011 ' Digits 5,4,3,2 HEX decode, 1 special decode
GoSub Config ' Configure display
' Now write data to the display
D5=0 : D4=0 : D3=0 : D2=0 ' Load counter with 0000 on start
For X = 0 TO 1000 ' Count from 0 to 1000
EN = 0 ' Enable data input
IF D2 > 9 Then D2=0 : D3=D3+1 ' Increment each higher digit # on 9
IF D3 > 9 Then D3=0 : D4=D4+1 ' value of each lower digit # for BCD
IF D4 > 9 Then D4=0 : D5=D5+1 ' counting
IF D5 > 9 Then D5=0' bright 5 4 3 2 :=OFF
ShiftOut DOUT, CLK, MSBFIRST, [%0000\4, D5\4, D4\4, D3\4, D2\4, $0\4]
EN = 1 ' Transfer data into display registers
Pause 20 ' Without pause, display counts from 0 to 9999 in ~6 seconds
D2=D2+1 ' Increment counter
Next X
Pause 500
Return
Help: ' Display H.E.L.P. while toggling brightness from 100% to 50%
CFG = %11101111 ' Digits 5,3,2,1 special decode, 4 HEX decode
GoSub Config ' Configure display
' Now write H.E.L.P. to display blinking 50% to 100% brightness
Y = %00001111 ' Setup bit 3 for toggling display brightness
For X = 0 TO 4 ' and all DP's ON
EN = 0 ' Enable data input
Y.0[3] = Y.0[3] ^ 1' Flip Y.bit.3 by XOR-ing with 1 [ 0=DIM, 1=BRIGHT ]
' Y = brightness & DP's 5 4 3 2 :=OFF
ShiftOut DOUT, CLK, MSBFIRST, [Y\4, $2\4, $E\4, $5\4, $8\4, $0\4]
EN = 1 ' Transfer data into display registers
Pause 200
Next X
Pause 500
Return
Ouch: ' Display OUCH while toggling brightness from 100% to 50%
CFG = %11010111 ' Special decode 4,2,1. 3,5 HEX decode
GoSub Config ' Configure display
' Now write OUCH to display
Y = %00001000 ' Set bit 3 for toggling brightness & all DP's OFF
For X = 0 TO 4
EN = 0 ' Enable data input
Y.0[3] = Y.0[3] ^ 1' Flip Y.bit.3 by XOR-ing with 1 [ 0=DIM, 1=BRIGHT ]
' 5 4 3 2 :=OFF
ShiftOut DOUT, CLK, MSBFIRST, [Y\4, $0\4, $A\4, $C\4, $2\4, $0\4]
' ^--- bit 3 of 4-bit value toggles brightness
EN = 1 ' Transfer data into display registers
Pause 200
Next X
Pause 500
Return
LampTest: ' Lamp test to display 8.8.:8.8.
CFG = %11000001 ' All digits normal HEX decode
GoSub Config ' Configure display
' Now write 8.8.:8.8.
EN = 0 ' 5=8 4=8 3=8 2=8 :=ON
ShiftOut DOUT, CLK, MSBFIRST, [$F\4, $8\4, $8\4, $8\4, $8\4, $2\4]
' ^-- bright display + all DP's ON
EN = 1 ' Transfer data into display registers
Pause 3000
' Now blink display ON & OFF 3 times
' Note: Toggling bit.0 of the 8-bit config byte toggles the
' display ON (1) & OFF (0) for normal/low power modes
For X = 0 TO 2
CFG = %11000000 ' All digits HEX decode / display off
GoSub Config ' Configure display
Pause 250
CFG = %11000001 ' All digits HEX decode / display ON
GoSub Config ' Configure display
Pause 250
Next X
Return
Clock: ' 24-hour clock times from 16:50 to 17:00 w/blinking colon
CFG = %11000011 ' 5,4,3,2 HEX decode, 1 special decode
GoSub Config ' Configure display
Y = 8 ' Used to toggle colon. 8 = ON, 0 = OFF
' Now write data to the display
D5=1 : D4=6 : D3=5 : D2=0 ' Set clock time to 16:50
For X = 0 TO 10 ' Display clock time from 16:50 to 17:00
EN = 0 ' Enable data input
IF D2 > 9 Then D2=0 : D3=D3+1 ' Increment each higher digit on 9
IF D3 > 5 Then D3=0 : D4=D4+1 ' Roll-over from 59 minutes
IF D4 > 9 Then D4=0 : D5=D5+1 ' Roll-over from hours to tens hours
IF D5 > 2 Then D5=0 ' Never > 2 for 10's hour digit
IF (D5 = 2) AND (D4 > 3) Then ' Roll-over from 23:59 to 00:00
D5 = 0 : D4 = 0
EndIF' 5=1 4=6 3=5 2=0 :=blinking
ShiftOut DOUT, CLK, MSBFIRST, [%0000\4, D5\4, D4\4, D3\4, D2\4, Y\4]
Y = Y ^ 8 ' 8^8=0, 0^8=8
EN = 1 ' Transfer data into display registers
Pause 250 ' Update frequency or clock ticks
D2=D2+1 ' Increment low digit counter
Next X
Pause 500
Return
Config:
EN = 0 ' Enable data input
ShiftOut DOUT, CLK, MSBFIRST, [CFG] ' Write to display config register
EN = 1 ' Transfer data into display registers
Return
End