' HC4LED.BS2 ' 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 (Connect to pin 1 for this demo program) ' Pin6 = Data (Connect to pin 0 for this demo program) ' ' ' 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 left) ' 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 BS2} ' {$PBASIC 2.5} Clock PIN 1 ' HC4LED module's Clock pin Dat PIN 0 ' HC4LED modules's Data pin value VAR Word ' Required; Holds value to display zeros VAR Bit ' Required; Determines if leading zeros are displayed cnt VAR Byte ' Required; Used by display routines segments VAR Byte (4) ' Required; Used by display routines & customer chars ' DO ' Repeat forever FOR value = 0 TO 1000 ' Count from 0 to 1000 GOSUB DisplayValue ' Display count on HC4LED module PAUSE 100 ' Wait 0.1 seconds NEXT ' Next count PAUSE 1000 ' Wait 1 second segments(0) = 28 ' 7 ' Setup to display "72°F" segments(1) = 109' 2 segments(2) = 15 ' ° segments(3) = 71 ' F GOSUB DisplaySegments ' Display custom characters PAUSE 2000 ' Wait 2 seconds LOOP ' Repeat forever STOP DisplayValue: ' Call with: ' value = (value to display) ' zeros = (0=No leading zeros; 1=Show leading zeros) FOR cnt = 0 TO 4 LOOKUP value DIG cnt, [126,24,109,61,27,55,115,28,127,31],segments(3-cnt) NEXT IF zeros = 0 THEN IF segments(0) = 126 THEN segments(0) = 0 IF segments(1) = 126 THEN segments(1) = 0 IF segments(2) = 126 THEN segments(2) = 0 ENDIF ENDIF ENDIF ENDIF DisplaySegments: ' Call with: ' segments(0) thru segments(3) set to custom character values ' segments(0) is on the left; segments(3) is on the right SHIFTOUT Dat, Clock, MSBFIRST,[segments(3), segments(2), segments(1), (segments(0) >> 1)\7] Dat = segments(0) & 1 HIGH Clock ' Clock MUST remain high for at LEAST 1 millisecond for the ' new data to be latched onto the display. PAUSE 1 RETURN