Sat May 18, 2013 11:18 pm
TITLE "MULTIPLEXING 7 SEGMENT DECODER"
list p = 16f877
include <p16f877.inc>
BANK0 macro
bcf STATUS,RP0
bcf STATUS,RP1
endm
BANK1 macro
bsf STATUS,RP0
bcf STATUS,RP1
endm
BANK2
macro
bcf STATUS,RP0
bsf STATUS,RP1
endm
BANK3 macro
bsf STATUS,RP0
bsf STATUS,RP1
endm
; **** EQUATES
DIGIT1 EQU 0x20
DIGIT2 EQU 0x21
DIGIT3 EQU 0x22
DIGIT4 EQU 0x23
COUNT EQU 0x24
DIGIT EQU 0x25
TEMP EQU 0x26
DELAY_TIME EQU 0x27
DATAVALUE EQU 0; INDIRECT ADDRESS
; ******
ORG 0
NOP
GOTO START
; MAIN ROUTINE
ORG 0x20
START CALL SET_DATA
CALL INIT ;INITIALISE PORTS
AGAIN MOVLW 4 ;SET CoUNT = 4
MOVWF COUNT
MOVLW 0x20 ;SET PoINTER To DATA
MOVWF FSR ;AND STORE
MOVLW 8 ;SET DIGIT To MSB
MOVWF DIGIT ;AND STORE
NEXT_DIGIT
MOVF DATAVALUE,W ;GET DIGIT
CALL GET_PATTERN ;DECODE
MOVWF PORTD ;AND OUTPUT
MOVF DIGIT,W ;GET DIGIT TO SWITCH ON
MOVWF PORTA ;AND SWITCH ON
CALL DELAY ;WAIT
CLRF PORTA ;CLEAR DISPLAy
INCF FSR ;POINT TO NEXT DIGIT
RRF DIGIT ;MOvE ENABLE TO NEXT DIGIT
DECF COUNT ;COUNT COUNT - 1
BTFSS STATUS,Z ;IF LAST START AGAIN
GOTO NEXT_DIGIT ;ELSE Do NExT
GOTO AGAIN ;AND REPEAT
MOVF DIGIT,W ;GET NUMBER BETWEEN 0 - 9
ANDLW 0x0F ;ONLY 4 LSBs
CALL GET_PATTERN ;DECODE
MOVWF PORTD ;OUTPUT
MOVLW 01 ;SELECT 1ST DIGIT
MOVWF PORTA ;AND oUTPUT
GOTO AGAIN ;REPEAT FOR EVER
; PORT INITIALISATION
INIT BANK1 ;SET TO BANK 1
CLRF TRISD ;SET PORT D To oUTPUT
MOVLW 06 ;MME PORT A DIGITAL
MOVWF ADCON1
CLRF TRISA ;AND PORT OUTPUT
BANK0 ;BAOK TO BANK 0
RETURN
;DECODE ROUTINE
GET_PATTERN
ADDWF PCL ;GOTO EQUIV PATTERN
RETLW 0x3F ;ZERo PATTERN
RETLW 0x06 ;oNE PATTERN
RETLW 0x5B ;TWo PATTERN
RETLW 0x4F ;THREE PATTERN
RETLW 0x66 ;FOUR PATTERN
RETLW 0x6D ;FIvE PATTERN
RETLW 0x7D ;SIx PATTERN
RETLW 0x07 ;SEvEN PATTERN
RETLW 0x7F ;EIGHT PATTERN
RETLW 0x67 ;NINE PATTERN
RETLW 0x40 ;INVALID DIGIT
RETLW 0x40 ;INvALID DIGIT
RETLW 0x40 ;PINvALID DIGIT
RETLW 0x40 ;INVALID DI3ITN
RETLW 0x40 ;INVALID DIGIT
RETLW 0x40 ;INvALID DIGIT
; SE TEST DATA
SET_DATA
MOVLW 0 ;-ZERoI
MOVWF DIGIT1 ;AND STORE
MOVLW 1 ;1
MOVWF DIGIT2 ;AND SToRE
MOVLW 2 ;2
MOVWF DIGIT3 ;AND SToRE
MOVLW 3 ;3
MOVWF DIGIT4 ;AND SToRE
RETURN
; DELAY ROUTIN
DELAY MOVWF TEMP ; SAVE
MOVLW 0xFF; SET DELAY TIME
MOVWF DELAY_TIME
WAIT INCFSZ DELAY_TIME ; COUNT DOWN
GOTO WAIT
MOVF TEMP,W ; RESTORE W
RETURN
END
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.