; ====================================================================
; File....... Three 74HC575 to three 7-seg dispays for 28X1 or 40X1
; Purpose.... Program to use three cascaded 74HC595 shift registers
; to drive three 7-segment displays
; Author..... Westaust55
; E-mail.....
; Started.... 24-10-2009
; Updated.... DD-MM-YYYY
; ===============================================
;
; -----[ Program Description ]---------------------------------------------
;
; A program to drive three 74HC575 to three 7-seg dispays and diplays values
; on three 7-segment displays to show the values from 0.00 thru 0.01 ... to 999.
;
;
; -----[ Revision History ]------------------------------------------------
; A. First written 24-10-2009
; B. Added Out Enabled pins for three 7 segment LEDs manufactured in a single package with shared leads
;
;
; -----[ I/O Definitions ]-------------------------------------------------
;
; - - - DIGITAL INPUT PINS - - -
;
; - - - DIGITAL OUTPUT PINS - - -
;
SYMBOL RegCl = 3 ; Shift Register Clear - Low to clear
SYMBOL OutEn2 = 2 ; Output Enable Digit2 (far left). Low to enable 100s Outputs
SYMBOL OutEn1 = 1 ; Output Enable Digit1 (ctr) Low to enable 10s Outputs
SYMBOL OutEn0 = 0 ; Output Enable Digit0 (far right) Low to enable units Outputs
SYMBOL latch = 5 ; latch data to 595 outputs
SYMBOL sclk = 6 ; serial clock on pin 6
SYMBOL sdata = 7 ; serial data on pin 7
;
; - - - ANALOGUE INPUT PINS - - -
;
;
; -----[ i2c Device Addressing ]-------------------------------------------------------
;
;
; -----[ Constants ]-------------------------------------------------------
;
;
;
; -----[ Variables ]-------------------------------------------------------
;
; define aliases names for variables used
SYMBOL bitcntr = b3 ; control for serial shifting of data out
SYMBOL digit = b4 ; extracted digit from 3 digit value 0 - 999
SYMBOL digout = b5 ; encoded value 7-seg display to the output with serial shifting
SYMBOL mask = b6 ;
SYMBOL decpnt = b7
;
; -----[ EEPROM Data ]-----------------------------------------------------
;
;
;
; -----[ Initialization ]--------------------------------------------------
;
Init:
disconnect
Low sclk ; make sure the clock and data lines are low in advance
Low sdata
' Low OutEn ; Enable the 74HC595 outputs
High RegCl ; Remove the 74HC595 clear signal
decpnt = 0
;
SetFreq k31
; -----[ Program Code ]----------------------------------------------------
;
Main:
FOR b2 = 1 TO 3 ; three decades to display 0.00 to 9.99, 00.0 to 99.9 and 000. to 999.
FOR w0 = 0 to 999 ; range of the display
; Demonstrate use of Output Enable and Clear Signals if count between 500 and 550
IF w0 > 500 AND w0 < 550 THEN
If b2 = 1 THEN ; First cycle disable outputs so no display
High OutEn0
High OutEn1
High OutEn2
ELSEIF b2 = 2 THEN ; Second cycle clear the shift registers
Low RegCl ; again the 7-seg displays are all off
ENDIF
ENDIF
IF w0 = 551 THEN ; restore at end of the "feature"demo period
' LOW OutEn0
' LOW OutEn1
' LOW OutEn2
HIGH RegCl
ENDIF
; Normal count and display portion of the code
digit = w0 // 10 ; extract units digit
IF b2 = 3 THEN
decpnt = 1
ENDIF
LOW OutEn0
GOSUB ShiftoutMSBFirst ; fetch the bit code for the current digit value and shift out
High OutEn0
digit = w0 // 100 / 10 ; extract the tens digit
IF b2 = 2 THEN
decpnt = 1
ENDIF
LOW OutEn1
GOSUB ShiftoutMSBFirst
High OutEn1
digit = w0 / 100 ; extract the hundreds digit
IF b2 = 1 THEN
decpnt = 1
ENDIF
LOW OutEn2
GOSUB ShiftoutMSBFirst
High OutEn2
pulsout latch,5
NEXT w0
NEXT b2
GOTO Main ; loop through the values 0.00 to 999 forever
END
;
; -----[ Subroutines ]-----------------------------------------------------
;
ShiftoutMSBfirst:
; First find the display code for 7-seg display corresponding to the digit value 0 -9
' LOOKUP digit, ($7D,$60,$5E,$7A,$63,$3B,$3F,$70,$7F,$7B), digout ; change $70 to $56 for different "7" appearance
LOOKUP digit, ($3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$67), digout
; change $70 to $56 for different "7" appearance
IF decpnt = 1 THEN
digout = digout OR $80 ; turn on bit 7 for decimal point
decpnt = 0
ENDIF
;
; Then shift data out serially - most significant bit first
FOR bitcntr = 1 TO 8 ; one loop per bit
mask = digout & $80 ; Mask out the MSB
LOW sdata
IF mask = 0 THEN skipMSB
HIGH sdata
skipMSB: pulsout sclk,1 ; pulse clock line for 10us
digout = digout * 2 ; shift value left ready for next bit
NEXT bitcntr
RETURN
;
;
;
; -----[ Interrupt Routines (if used) ]-------------------------------------
;
;Interrupt:
; RETURN
; =================================================
; THE END
; =================================================