' ========================================================================= ' ' File...... HC4LED.SXB ' Compiler.. SXB Version 1.50 ' Purpose... Demonostrate use of HC4LED display module ' Author.... Terry Hitt ' E-mail.... terry@hittconsulting.com ' Started... ' Updated... ' ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' HC4LED Pinout: ' Pin1 = +5VDC (White wire) ' Pin2 = Gnd ' Pin3 = Blank (Must connect to Gnd to enable display) ' Pin4 = No Connection ' Pin5 = Clock (Connect to RA.0 for this demo program) ' Pin6 = Data (Connect to RA.1 for this demo program) ' ' ' 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 "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 ' ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28,OSC4MHZ,TURBO,STACKX,OPTIONX FREQ 4_000_000 ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- Clk VAR RA.0 Dat VAR RA.1 ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- BLANK CON 0 MINUS CON 1 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- segments VAR Byte (4) tempWord VAR Word cnt VAR Byte isNegative VAR Bit value VAR Word ' ========================================================================= PROGRAM Start NOSTARTUP ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- Delay2Sec SUB 0 ' Waits for 2 seconds DisplayValue SUB 1, 2 ' Variable or value as parameter DisplaySegments SUB 4 ' Segment values LEDOut SUB 1 ' Shifts out 1 digit ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: DO DisplaySegments $7F, $7F, $7F, $7F Delay2Sec DisplaySegments 0, 0, 0, 0 Delay2Sec ' Show custom(non-numeric) message DisplaySegments 91,103,98,79 ' HELP Delay2Sec ' Show leading zero blanking DisplayValue 1 Delay2Sec DisplayValue 12 Delay2Sec DisplayValue 123 Delay2Sec DisplayValue 1234 Delay2Sec ' Show displaying word variable value FOR value = 0 to 9999 DisplayValue value NEXT Delay2Sec FOR value = -1 TO -999 STEP -1 DisplayValue value PAUSE 20 NEXT Delay2Sec LOOP END ' ------------------------------------------------------------------------- ' Subroutine Code ' ------------------------------------------------------------------------- Delay2Sec: PAUSE 2000 RETURN ' ------------------------------------------------------------------------- ' Subroutines to control HC4LED display ' ------------------------------------------------------------------------- DisplayValue: IF __PARAMCNT = 1 THEN tempWord = __PARAM1 ELSE tempWord = __WPARAM12 ENDIF isNegative = tempWord.15 IF isNegative = 1 THEN tempWord = -tempWord ENDIF PUT segments, BLANK, BLANK, BLANK, BLANK DO WHILE tempWord >= 1000 INC segments(3) tempWord = tempWord - 1000 LOOP DO WHILE tempWord >= 100 INC segments(2) tempWord = tempWord - 100 LOOP DO WHILE tempWord >= 10 INC segments(1) tempWord = tempWord - 10 LOOP segments(0) = tempWord_LSB FOR cnt = 0 TO 3 READ DigitSegs + segments(cnt), segments(cnt) NEXT IF isNegative = 1 THEN segments(3) = MINUS cnt = 2 ELSE cnt = 3 ENDIF BlankZeros: IF segments(cnt) = 126 THEN ' IF digit is Zero... IF isNegative = 1 THEN PUT segments(cnt), MINUS, BLANK ELSE segments(cnt) = BLANK ' make it Blank ENDIF ELSE cnt = 1 ' Set counter to done value ENDIF DJNZ cnt,BlankZeros GOTO DisplayArray DisplaySegments: PUT segments, __PARAM4, __PARAM3, __PARAM2, __PARAM1 DisplayArray: LOW Clk LEDOut segments(0) LEDOut segments(1) LEDOut segments(2) cnt = segments(3) >> 1 SHIFTOUT Dat, Clk, MSBFIRST, cnt\7 PAUSEUS 5 Dat = segments(3).0 PAUSEUS 5 HIGH Clk PAUSE 2 RETURN LEDOut: cnt = __PARAM1 SHIFTOUT Dat, Clk, MSBFIRST, cnt RETURN ' ------------------------------------------------------------------------- ' Data ' ------------------------------------------------------------------------- DigitSegs: DATA 126,24,109,61,27,55,115,28,127,31