Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
asm
LIST
P=16F877A
INCLUDE <P16F877A.INC>
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC
CBLOCK 0x20
Contador
DlaySwCountA
DlaySwCountB
count
R0
R1
R2
L_byte
H_byte
temp
ENDC
;************************************************************************************
ORG
goto
ORG
goto
0
Inicio
4
ServicioInterrupcion
call
bsf
bsf
bcf
clrf
call
movlw
movwf
Display
STATUS,RP0
PORTB,7
STATUS,RP0
Contador
VisualizaContador
b'10001000'
INTCON
Inicio
Principal
sleep
goto
Principal
FinInterrupcion
bcf
INTCON,RBIF
; Limpia flag de reconocimiento RBIF.
retfie
;************************************************************************************
Delay
movlw
d'10'
movwf
DlaySwCountB
ExtLoop1ms
movlw
d'200'
movwf
DlaySwCountA
IntLoop1ms
nop
decfsz DlaySwCountA,F
goto
IntLoop1ms
decfsz DlaySwCountB,F
goto
ExtLoop1ms
return
;************************************************************************************
B2_BCD
bcf
STATUS,0
; clear the carry bit
movlw
.16
movwf
count
clrf
R0
clrf
R1
clrf
R2
loop16
Pgina 1
RBI.asm
rlf
rlf
rlf
rlf
rlf
L_byte, f
H_byte, f
R2, f
R1, f
R0, f
decfsz
goto
retlw
count, f
adjDEC
0
movlw
movwf
call
R2
FSR
adjBCD
movlw
movwf
call
R1
FSR
adjBCD
movlw
movwf
call
R0
FSR
adjBCD
goto
loop16
adjDEC
; no bank switching, always
; indirect access for RAM
adjBCD
movlw
3
addwf
0,W
movwf
temp
btfsc
temp,3
; test if result > 7
movwf
INDF
movlw
30
addwf
0,W
movwf
temp
btfsc
temp,7
; test if result > 7
movwf
INDF
; save as MSD
retlw
0
;************************************************************************************
Display
movf
PORTC,W
;present sink value in w
clrf
PORTC
;disable all digits sinks
andlw
07h
movwf
TempC
;save sink value in tempC
bsf
TempC,3
;preset for lsd sink
rrf
TempC,F
;determine next sink value
btfss
STATUS,C
;c=1?
bcf
TempC,2
;no then reset LSD sink
;***************************************************************************
btfsc
TempC,0
;else see if Msd
goto
UpdCent
;yes then do Msd
;***************************************************************************
btfsc
TempC,1
;see if 3rdLsd
goto
UpdDec
;yes then do Msd
;***************************************************************************
UpdUnidad
movf
BcdLow,W
;get Lsd in w
andlw
0x0f
;
/
goto
DisplayOut
;enable display
;***************************************************************************
UpdDec
call
ChkDecZero
;msd = 0 & 2 lsd 0?
btfss
STATUS,Z
;yes then skip
swapf
BcdLow,W
;get 2nd Lsd in w
andlw
0x0f
;mask rest
goto
DisplayOut
;enable display
;***************************************************************************
UpdCent
movf
BcdHigh,W
;get Msd in w
andlw
0x0f
;mask low nibble
btfsc
STATUS,Z
;msd != 0 then skip
movlw
0x0a
return
;***************************************************************************
DisplayOut
call
display_table
;get digit output
movwf
PORTB
;drive leds
movf
TempC,W
;get sink value in w
movwf
PORTC
;***************************************************************************
ChkDecZero
call
ChkCentZero
;msd = 0?
btfss
STATUS,Z
;yes then skip
return
;else return
swapf
BcdLow,W
;get 2nd lsd
Pgina 2
RBI.asm
andlw
0x0f
;mask of LSD
btfss
STATUS,Z
;0? then skip
return
retlw
.10
;else return with 10
;***************************************************************************
ChkCentZero
movf
BcdHigh,W
;get Msd in w
btfss
STATUS,Z
;= 0? skip
return
;else return
retlw
.10
;ret with 10
;***************************************************************************
display_table
addwf
PCL,f
;
W + PCL -> PCL
retlw
b'00111111' ; '0'
retlw
b'00000110' ; '1'
retlw
b'01011011' ; '2'
retlw
b'01001111' ; '3'
retlw
b'01100110' ; '4'
table for segment patterns
retlw
b'01101101' ; '5'
retlw
b'01111101' ; '6'
retlw
b'00000111' ; '7'
retlw
b'01111111' ; '8'
retlw
b'01100111' ; '9'
retlw
b'00000000' ; '.'
retlw
b'10000000'
; '.'
;---------------------------------------------------------------------------END
Pgina 3