' HC4LED.BS1 ' This program demonstrates the use of the HC4LED display module ' HC4LED Pinout: ' Pin1 = +5VDC (White wire) ' Pin2 = Gnd ' Pin3 = Blank (Must connect to Gnd to enable display) ' Pin4 = No Connection ' Pin5 = Clock ' Pin6 = Data ' ' ' To display values: ' Set the "zeros" variable to 0=No leading zeros; or 1=Show leading zeros ' Set the variable "value" to 0 to 9999 ' Then use "GOSUB DisplayValue" to show the value on the display ' ' Each segment of the display is addressable, so you can create letters ' and symbols. ' To display custom symbols: ' Set the variables "segments(0)" thru "segments(3)" (segments(0) is on the right) ' simply add the segment values that you want on ' Then use "GOSUB DisplaySegments" to show the segments on the display ' ' ---4--- ' | | ' 2 8 ' | | ' |---1---| ' | | ' 64 16 ' | | ' --32--- ' ' For example "F" would be 4+2+1+64 = 71 ' ' {$STAMP BS1} ' {$PBASIC 1.0} SYMBOL Clk = 0 'Display Clock is pin 0 SYMBOL Dat = PIN1 'Display Data is pin 1 SYMBOL Cnt = B2 'Counter variable for DisplayDigit subroutine SYMBOL digit = B3 'Current value digit SYMBOL value = W2 'Value to be displayed ' Next available variables are: BIT8,B6,W3 Start: DIRS = %00000011 'Set Clock and Data pins as outputs rest as inputs HIGH Clk Main: ' Display HELP LOW Clk B0 = 79 GOSUB DisplaySegments PULSOUT Clk,1 ' Pulsout last bit except for last digit B0 = 98 GOSUB DisplaySegments PULSOUT Clk,1 B0 = 103 GOSUB DisplaySegments PULSOUT Clk,1 B0 = 91 GOSUB DisplaySegments HIGH Clk ' Keep Clk high to latch in new display data ' Show HELP for 5 seconds PAUSE 5000 ' Display values from 1000 to 0 FOR value = 1000 TO 0 STEP -1 GOSUB DisplayValue NEXT GOTO Main DisplayValue: ' Call with "value" set to the value to be displayed LOW Clk digit = value // 10 GOSUB DisplayDigit PULSOUT Clk,1 digit= value / 10 // 10 GOSUB DisplayDigit PULSOUT Clk,1 digit= value / 100 // 10 GOSUB DisplayDigit PULSOUT Clk,1 digit= value / 1000 // 10 GOSUB DisplayDigit HIGH Clk RETURN DisplayDigit: ' Called by DisplayValue subroutine LOOKUP digit,(126,24,109,61,27,55,115,28,127,31),B0 DisplaySegments: ' Call with B0 containing the segments for the next digit FOR cnt = 1 TO 7 Dat = BIT7 PULSOUT Clk,1 B0 = B0 * 2 NEXT Dat = BIT7 RETURN