__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _WRT_ENABLE_OFF & _LVP_ON & _CPD_OFF
list p=16f873 ; list directive to define processor
#include <p16f873.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _XT_OSC & _WRT_ENABLE_OFF & _LVP_OFF & _CPD_OFF
;**********************************************************************
STATUS equ h'03' ;address of STATUS
PORTA equ h'05' ;address of PORTA
PORTB equ h'06' ;address of PORTB
PORTC equ h'07' ;address of PORTC
INTCON equ h'0B' ;address of INTCON
ADCON0 equ h'1F' ;address of ADCON0
PIR1 equ h'0c' ;address of PIR1
TRISA equ h'85' ;address of TRISA
TRISB equ h'86' ;address of TRISB
TRISC equ h'87' ;address of TRISC
PIE1 equ h'8c' ;address of PIE1
ADRESL equ h'9e' ;address of ADRESL
ADCON1 equ h'9f' ;address of ADCON1
CBLOCK 0X20 ;define a group of GPR
w_temp
status_temp
PRESET
NOW
TMP
DELAY2
DELAY3
DELAY4
DELAY42
SEG0
SEG1
SEG2
SEG3
SEG4
SEG5
SEG6
SEG7
SEG8
SEG9
ENDC
;**********************************************************************
RESET_VECTOR CODE 0x000 ; processor reset vector
goto START ; go to beginning of program
INT_VECTOR CODE 0x004 ; interrupt vector location
goto INT
BEGAN CODE 0X005
goto START
;**********************************************************************
START
MOVLW b'00001110'
MOVWF ADCON1
MOVLW b'01000001'
MOVWF ADCON0
MOVLW b'11000000'
MOVWF INTCON
MOVLW b'01000000'
MOVWF PIE1
MOVLW b'00000000'
MOVWF PIR1
MOVLW b'00000001'
MOVWF TRISA
MOVLW b'00000000'
MOVWF TRISB
MOVLW b'01111111'
MOVWF TRISC
movlw b'11000000'
MOVWF SEG0
movlw b'11111001'
MOVWF SEG1
movlw b'10100100'
MOVWF SEG2
movlw b'10110000'
MOVWF SEG3
movlw b'10011001'
MOVWF SEG4
movlw b'10010010'
MOVWF SEG5
movlw b'10000010'
MOVWF SEG6
movlw b'11111000'
MOVWF SEG7
movlw b'10000000'
MOVWF SEG8
movlw b'10010000'
MOVWF SEG9
MOVF PORTC,0
MOVWF PRESET
CALL DISP1
goto MAIN
;**********************************************************************
INT
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
bcf STATUS,RP0 ; ensure file register bank set to 0
movwf status_temp ; save off contents of STATUS register
; isr code can go here or be located as a call subroutine elsewhere
bcf STATUS,RP0 ; ensure file register bank set to 0
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
;**********************************************************************
;**************** MAIN PROGRAM *****************************
MAIN
MOVLW b'01000101'
MOVWF ADCON0 ;start conversion
CALL Delay2 ;delay 9TAD=18us
MOVF ADRESL,0 ;read the converted value
MOVWF NOW
CALL DISP2
MOVF PRESET,0
SUBWF NOW
BTFSS STATUS,C
BSF PORTA,5
NOP
BTFSC STATUS,C
BSF PORTB,7
NOP
CALL Delay3 ;delay 2TAD=4us
GOTO MAIN
;***********************************************************
;**************** SUBROUTINES ******************************
DISP1
MOVF PRESET,0
MOVWF TMP
CALL SEVENSEG1
BSF PORTA,1
CALL Delay4 ;delay T=1mS
CALL SEVENSEG2
BSF PORTA,2
CALL Delay4 ;delay T=1mS
RETURN
DISP2
MOVF NOW,0
MOVWF TMP
CALL SEVENSEG1
BSF PORTA,3
CALL Delay4 ;delay T=1mS
CALL SEVENSEG2
BSF PORTA,4
CALL Delay4 ;delay T=1mS
RETURN
SEVENSEG1
MOVLW d'90'
SUBWF TMP,1
BTFSS STATUS,C
GOTO NINE
MOVLW d'80'
SUBWF TMP,1
BTFSS STATUS,C
GOTO EGHIT
MOVLW d'70'
SUBWF TMP,1
BTFSS STATUS,C
GOTO SEVEN
MOVLW d'60'
SUBWF TMP,1
BTFSS STATUS,C
GOTO SIX
MOVLW d'50'
SUBWF TMP,1
BTFSS STATUS,C
GOTO FIVE
MOVLW d'40'
SUBWF TMP,1
BTFSS STATUS,C
GOTO FOUR
MOVLW d'30'
SUBWF TMP,1
BTFSS STATUS,C
GOTO THREE
MOVLW d'20'
SUBWF TMP,1
BTFSS STATUS,C
GOTO TWO
MOVLW d'10'
SUBWF TMP,1
BTFSS STATUS,C
GOTO ONE
MOVLW d'00'
SUBWF TMP,1
BTFSS STATUS,C
GOTO ZERO
RETURN
SEVENSEG2
MOVLW d'0'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO ZERO
MOVLW d'1'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO ONE
MOVLW d'2'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO TWO
MOVLW d'3'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO THREE
MOVLW d'4'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO FOUR
MOVLW d'5'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO FIVE
MOVLW d'6'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO SIX
MOVLW d'7'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO SEVEN
MOVLW d'8'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO EGHIT
MOVLW d'9'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO NINE
RETURN
NINE
MOVF SEG9,0
MOVWF PORTB
RETURN
EGHIT
MOVF SEG8,0
MOVWF PORTB
RETURN
SEVEN
MOVF SEG7,0
MOVWF PORTB
RETURN
SIX
MOVF SEG6,0
MOVWF PORTB
RETURN
FIVE
MOVF SEG5,0
MOVWF PORTB
RETURN
FOUR
MOVF SEG4,0
MOVWF PORTB
RETURN
THREE
MOVF SEG3,0
MOVWF PORTB
RETURN
TWO
MOVF SEG2,0
MOVWF PORTB
RETURN
ONE
MOVF SEG1,0
MOVWF PORTB
RETURN
ZERO
MOVF SEG0,0
MOVWF PORTB
RETURN
Delay2 ;delay 9TAD=18us
MOVLW d'36'
MOVWF DELAY2
DECFSZ DELAY2,1
GOTO $-1
RETURN
Delay3 ;delay 2TAD=4us
MOVLW d'8'
MOVWF DELAY3
DECFSZ DELAY3,1
GOTO $-1
RETURN
Delay4 ;delay 1ms
MOVLW d'4'
MOVWF DELAY4
CALL Delay4_2
DECFSZ DELAY4,1
GOTO $-2
RETURN
Delay4_2
MOVLW d'128'
MOVWF DELAY42
DECFSZ DELAY42,1
GOTO $-1
RETURN
;**********************************************************************
END ; directive 'end of program'
include "P16F873.inc"
list p=16f873 ; list directive to define processor
#include <p16f873.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _XT_OSC & _WRT_ENABLE_OFF & _LVP_OFF & _CPD_OFF
;**********************************************************************
CBLOCK 0X20 ;define a group of GPR
w_temp
status_temp
PRESET
NOW
TMP
DELAY2
DELAY3
DELAY4
DELAY42
SEG0
SEG1
SEG2
SEG3
SEG4
SEG5
SEG6
SEG7
SEG8
SEG9
ENDC
;**********************************************************************
RESET_VECTOR CODE 0x000 ; processor reset vector
goto START ; go to beginning of program
INT_VECTOR CODE 0x004 ; interrupt vector location
goto INT
BEGAN CODE 0X005
goto START
;**********************************************************************
START
MOVLW b'00001110'
MOVWF ADCON1
MOVLW b'01000001'
MOVWF ADCON0
MOVLW b'11000000'
MOVWF INTCON
MOVLW b'01000000'
MOVWF PIE1
MOVLW b'00000000'
MOVWF PIR1
MOVLW b'00000001'
MOVWF TRISA
MOVLW b'00000000'
MOVWF TRISB
MOVLW b'01111111'
MOVWF TRISC
movlw b'11000000'
MOVWF SEG0
movlw b'11111001'
MOVWF SEG1
movlw b'10100100'
MOVWF SEG2
movlw b'10110000'
MOVWF SEG3
movlw b'10011001'
MOVWF SEG4
movlw b'10010010'
MOVWF SEG5
movlw b'10000010'
MOVWF SEG6
movlw b'11111000'
MOVWF SEG7
movlw b'10000000'
MOVWF SEG8
movlw b'10010000'
MOVWF SEG9
MOVF PORTC,0
MOVWF PRESET
CALL DISP1
goto MAIN
;**********************************************************************
INT
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
bcf STATUS,RP0 ; ensure file register bank set to 0
movwf status_temp ; save off contents of STATUS register
; isr code can go here or be located as a call subroutine elsewhere
bcf STATUS,RP0 ; ensure file register bank set to 0
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
;**********************************************************************
;**************** MAIN PROGRAM *****************************
MAIN
MOVLW b'01000101'
MOVWF ADCON0 ;start conversion
CALL Delay2 ;delay 9TAD=18us
MOVF ADRESL,0 ;read the converted value
MOVWF NOW
CALL DISP2
MOVF PRESET,0
SUBWF NOW
BTFSS STATUS,C
BSF PORTA,5
NOP
BTFSC STATUS,C
BSF PORTB,7
NOP
CALL Delay3 ;delay 2TAD=4us
GOTO MAIN
;***********************************************************
;**************** SUBROUTINES ******************************
DISP1
MOVF PRESET,0
MOVWF TMP
CALL SEVENSEG1
BSF PORTA,1
CALL Delay4 ;delay T=1mS
CALL SEVENSEG2
BSF PORTA,2
CALL Delay4 ;delay T=1mS
RETURN
DISP2
MOVF NOW,0
MOVWF TMP
CALL SEVENSEG1
BSF PORTA,3
CALL Delay4 ;delay T=1mS
CALL SEVENSEG2
BSF PORTA,4
CALL Delay4 ;delay T=1mS
RETURN
SEVENSEG1
MOVLW d'90'
SUBWF TMP,1
BTFSS STATUS,C
GOTO NINE
MOVLW d'80'
SUBWF TMP,1
BTFSS STATUS,C
GOTO EGHIT
MOVLW d'70'
SUBWF TMP,1
BTFSS STATUS,C
GOTO SEVEN
MOVLW d'60'
SUBWF TMP,1
BTFSS STATUS,C
GOTO SIX
MOVLW d'50'
SUBWF TMP,1
BTFSS STATUS,C
GOTO FIVE
MOVLW d'40'
SUBWF TMP,1
BTFSS STATUS,C
GOTO FOUR
MOVLW d'30'
SUBWF TMP,1
BTFSS STATUS,C
GOTO THREE
MOVLW d'20'
SUBWF TMP,1
BTFSS STATUS,C
GOTO TWO
MOVLW d'10'
SUBWF TMP,1
BTFSS STATUS,C
GOTO ONE
MOVLW d'00'
SUBWF TMP,1
BTFSS STATUS,C
GOTO ZERO
RETURN
SEVENSEG2
MOVLW d'0'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO ZERO
MOVLW d'1'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO ONE
MOVLW d'2'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO TWO
MOVLW d'3'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO THREE
MOVLW d'4'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO FOUR
MOVLW d'5'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO FIVE
MOVLW d'6'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO SIX
MOVLW d'7'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO SEVEN
MOVLW d'8'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO EGHIT
MOVLW d'9'
SUBWF TMP,1
BTFSC STATUS,Z
GOTO NINE
RETURN
NINE
MOVF SEG9,0
MOVWF PORTB
RETURN
EGHIT
MOVF SEG8,0
MOVWF PORTB
RETURN
SEVEN
MOVF SEG7,0
MOVWF PORTB
RETURN
SIX
MOVF SEG6,0
MOVWF PORTB
RETURN
FIVE
MOVF SEG5,0
MOVWF PORTB
RETURN
FOUR
MOVF SEG4,0
MOVWF PORTB
RETURN
THREE
MOVF SEG3,0
MOVWF PORTB
RETURN
TWO
MOVF SEG2,0
MOVWF PORTB
RETURN
ONE
MOVF SEG1,0
MOVWF PORTB
RETURN
ZERO
MOVF SEG0,0
MOVWF PORTB
RETURN
Delay2 ;delay 9TAD=18us
MOVLW d'36'
MOVWF DELAY2
DECFSZ DELAY2,1
GOTO $-1
RETURN
Delay3 ;delay 2TAD=4us
MOVLW d'8'
MOVWF DELAY3
DECFSZ DELAY3,1
GOTO $-1
RETURN
Delay4 ;delay 1ms
MOVLW d'4'
MOVWF DELAY4
CALL Delay4_2
DECFSZ DELAY4,1
GOTO $-2
RETURN
Delay4_2
MOVLW d'128'
MOVWF DELAY42
DECFSZ DELAY42,1
GOTO $-1
RETURN
;**********************************************************************
END ; directive 'end of program'
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?