added clock counter
This commit is contained in:
parent
d4a38ac95f
commit
96bee98513
225
cuenta/main.asm
225
cuenta/main.asm
|
|
@ -4,10 +4,10 @@ LIST P=18F4550, F=INHX32 ; Specify processor and hex format
|
||||||
CONFIG FOSC = HS ; Use internal oscillator, RA6 as clock output
|
CONFIG FOSC = HS ; Use internal oscillator, RA6 as clock output
|
||||||
CONFIG WDT = OFF ; Watchdog Timer off
|
CONFIG WDT = OFF ; Watchdog Timer off
|
||||||
CONFIG LVP = OFF ; Low-Voltage Programming off
|
CONFIG LVP = OFF ; Low-Voltage Programming off
|
||||||
CONFIG MCLRE = OFF ; MCLR pin disabled, RE3 input enabled
|
CONFIG MCLRE = ON ; MCLR pin disabled, RE3 input enabled
|
||||||
;CONFIG PBADEN = OFF
|
;CONFIG PBADEN = OFF
|
||||||
|
|
||||||
ORG 0x00 ; Program starts at address 0
|
|
||||||
ROTA1 EQU 0x01
|
ROTA1 EQU 0x01
|
||||||
ROTA2 EQU 0x02
|
ROTA2 EQU 0x02
|
||||||
ROTA3 EQU 0x04
|
ROTA3 EQU 0x04
|
||||||
|
|
@ -18,13 +18,18 @@ R1 EQU 0x020
|
||||||
R2 EQU 0x021
|
R2 EQU 0x021
|
||||||
R3 EQU 0x024
|
R3 EQU 0x024
|
||||||
CUENTA EQU 0x022
|
CUENTA EQU 0x022
|
||||||
|
CUENTA2 EQU 0x034
|
||||||
TEMP EQU 0x23
|
TEMP EQU 0x23
|
||||||
DISP0 EQU 0x30
|
DISP0 EQU 0x30
|
||||||
DISP1 EQU 0x31
|
DISP1 EQU 0x31
|
||||||
DISP2 EQU 0x32
|
DISP2 EQU 0x32
|
||||||
DISP3 EQU 0x33
|
DISP3 EQU 0x33
|
||||||
|
|
||||||
|
ORG 0x0000
|
||||||
|
goto Start
|
||||||
|
|
||||||
|
ORG 0x0008
|
||||||
|
goto loop
|
||||||
|
|
||||||
Start:
|
Start:
|
||||||
; Initialize PORTB
|
; Initialize PORTB
|
||||||
|
|
@ -32,37 +37,43 @@ Start:
|
||||||
CLRF LATD ; Clear PORTB outputs
|
CLRF LATD ; Clear PORTB outputs
|
||||||
|
|
||||||
CLRF LATB
|
CLRF LATB
|
||||||
BCF INTCON2, 7
|
BCF INTCON2, RBPU
|
||||||
MOVLW 0xff
|
MOVLW 0xff
|
||||||
MOVWF TRISB ; set port b to input
|
MOVWF TRISB ; set port b to input
|
||||||
movlw 0x0f
|
movlw 0x0f
|
||||||
movwf ADCON1
|
movwf ADCON1
|
||||||
|
|
||||||
|
clrf LATA
|
||||||
|
clrf TRISA
|
||||||
|
|
||||||
|
bsf RCON, IPEN ; enable priority modes
|
||||||
|
bsf INTCON, RBIF ; RB Port change interrupt
|
||||||
|
bsf INTCON, PEIE ; enable peripheral interrupts
|
||||||
|
bsf INTCON, GIE ; enable global interrupts
|
||||||
|
bsf INTCON2, RBIP ; rb to high priority
|
||||||
|
|
||||||
clrf LATE
|
clrf LATE
|
||||||
clrf TRISE
|
clrf TRISE
|
||||||
|
clrf CUENTA2
|
||||||
clrf CUENTA
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
;movlw 0x17
|
movf PORTB, W
|
||||||
;movwf CUENTA
|
bcf INTCON, RBIF
|
||||||
;call Delay
|
clrf CUENTA
|
||||||
;call sevensw
|
call splitDigit
|
||||||
;movwf PORTD
|
call Delay
|
||||||
;goto loop
|
|
||||||
movf PORTB, W
|
movf PORTB, W
|
||||||
xorlw ROTA1
|
xorlw ROTA1
|
||||||
btfsc STATUS, Z
|
btfsc STATUS, Z
|
||||||
goto leftright
|
goto hexa ; cuenta 1
|
||||||
xorlw ROTA2^ROTA1
|
xorlw ROTA2^ROTA1
|
||||||
btfsc STATUS, Z
|
btfsc STATUS, Z
|
||||||
goto right
|
goto decimal ; cuenta 2
|
||||||
xorlw ROTA2^ROTA3
|
xorlw ROTA2^ROTA3
|
||||||
btfsc STATUS, Z
|
btfsc STATUS, Z
|
||||||
goto left
|
goto des ; cuenta 3 wip
|
||||||
xorlw ROTA3^ROTA4
|
xorlw ROTA3^ROTA4
|
||||||
btfsc STATUS, Z
|
btfsc STATUS, Z
|
||||||
goto alternate
|
goto alternate
|
||||||
|
|
@ -74,74 +85,66 @@ loop:
|
||||||
goto outcenter
|
goto outcenter
|
||||||
goto loop
|
goto loop
|
||||||
|
|
||||||
leftright:
|
hexa:
|
||||||
CALL Delay ; Delay
|
call splitDigit
|
||||||
RLCF PORTD, f
|
call Delay
|
||||||
BTFSS STATUS,0
|
incf CUENTA, F
|
||||||
GOTO leftright ; Repeat the loop
|
call Delay
|
||||||
lright:
|
goto hexa
|
||||||
CALL Delay ; Delay
|
|
||||||
RRCF PORTD, F
|
|
||||||
BTFSS STATUS,0
|
|
||||||
GOTO lright ; Repeat the loop
|
|
||||||
return
|
|
||||||
|
|
||||||
left:
|
des:
|
||||||
MOVLW 0x80
|
clrf CUENTA
|
||||||
MOVWF PORTD
|
clrf CUENTA2
|
||||||
rl: CALL Delay ; Delay
|
rl:
|
||||||
RRCF PORTD, F
|
call splitDigit
|
||||||
BTFSS STATUS,0
|
call Delay
|
||||||
GOTO rl ; Repeat the loop
|
|
||||||
return
|
|
||||||
|
|
||||||
right:
|
|
||||||
incf CUENTA, W
|
incf CUENTA, W
|
||||||
daw
|
daw
|
||||||
movwf CUENTA
|
movwf CUENTA
|
||||||
|
xorlw 0x60
|
||||||
|
btfss STATUS, Z
|
||||||
|
goto rl
|
||||||
|
clrf CUENTA
|
||||||
|
incf CUENTA2, W
|
||||||
|
daw
|
||||||
|
movwf CUENTA2
|
||||||
|
xorlw 0x60
|
||||||
|
btfsc STATUS, Z
|
||||||
|
return
|
||||||
|
goto rl
|
||||||
|
|
||||||
|
decimal:
|
||||||
call splitDigit
|
call splitDigit
|
||||||
call Delay
|
call Delay
|
||||||
CALL Delay
|
incf CUENTA, W
|
||||||
goto right
|
daw
|
||||||
|
movwf CUENTA
|
||||||
|
Call Delay
|
||||||
|
goto decimal
|
||||||
|
|
||||||
alternate:
|
alternate:
|
||||||
movlw 0xaa
|
movlw 0xff
|
||||||
movwf PORTD
|
movwf CUENTA
|
||||||
|
call splitDigit
|
||||||
call Delay
|
call Delay
|
||||||
movlw 0x55
|
rl2:
|
||||||
movwf PORTD
|
call splitDigit
|
||||||
call Delay
|
call Delay
|
||||||
return
|
decfsz CUENTA
|
||||||
|
goto rl2
|
||||||
|
goto alternate
|
||||||
|
|
||||||
centerout:
|
centerout: ;; clock
|
||||||
movlw 0x18
|
|
||||||
movwf PORTD
|
|
||||||
call Delay
|
|
||||||
movlw 0x24
|
|
||||||
movwf PORTD
|
|
||||||
call Delay
|
|
||||||
movlw 0x42
|
|
||||||
movwf PORTD
|
|
||||||
call Delay
|
|
||||||
movlw 0x81
|
|
||||||
movwf PORTD
|
|
||||||
call Delay
|
|
||||||
return
|
return
|
||||||
|
|
||||||
outcenter:
|
outcenter:
|
||||||
movlw 0x81
|
call splitDigit
|
||||||
movwf PORTD
|
|
||||||
call Delay
|
call Delay
|
||||||
movlw 0x42
|
incf CUENTA, W
|
||||||
movwf PORTD
|
daw
|
||||||
call Delay
|
movwf CUENTA
|
||||||
movlw 0x24
|
Call Delay
|
||||||
movwf PORTD
|
goto decimal
|
||||||
call Delay
|
|
||||||
movlw 0x18
|
|
||||||
movwf PORTD
|
|
||||||
call Delay
|
|
||||||
return
|
|
||||||
|
|
||||||
splitDigit:
|
splitDigit:
|
||||||
movf CUENTA, W
|
movf CUENTA, W
|
||||||
|
|
@ -150,12 +153,20 @@ splitDigit:
|
||||||
swapf CUENTA, W
|
swapf CUENTA, W
|
||||||
andlw 0x0f
|
andlw 0x0f
|
||||||
movwf DISP1
|
movwf DISP1
|
||||||
|
movf CUENTA2, W
|
||||||
|
andlw 0x0f
|
||||||
|
movwf DISP2
|
||||||
|
swapf CUENTA2, W
|
||||||
|
andlw 0x0f
|
||||||
|
movwf DISP3
|
||||||
return
|
return
|
||||||
|
|
||||||
disp_delay:
|
disp_delay:
|
||||||
movlw D'250'
|
movlw D'250'
|
||||||
movwf R3
|
movwf R3
|
||||||
disp_delay_inner:
|
disp_delay_inner:
|
||||||
|
NOP
|
||||||
|
NOP
|
||||||
NOP
|
NOP
|
||||||
NOP
|
NOP
|
||||||
decfsz R3, F
|
decfsz R3, F
|
||||||
|
|
@ -163,11 +174,15 @@ disp_delay_inner:
|
||||||
return
|
return
|
||||||
|
|
||||||
sevensw:
|
sevensw:
|
||||||
movlw high(sevensw)
|
movlw high(sevenjmp)
|
||||||
movwf PCLATH
|
movwf PCLATH
|
||||||
movf TEMP, W
|
movf TEMP, W
|
||||||
addwf TEMP, W
|
addwf TEMP, W
|
||||||
addwf PCL, F
|
addlw low(sevenjmp)
|
||||||
|
btfsc STATUS, 0
|
||||||
|
incf PCLATH, 1
|
||||||
|
movwf PCL
|
||||||
|
sevenjmp:
|
||||||
retlw 3Fh
|
retlw 3Fh
|
||||||
retlw 06h
|
retlw 06h
|
||||||
retlw 5Bh
|
retlw 5Bh
|
||||||
|
|
@ -175,15 +190,17 @@ sevensw:
|
||||||
retlw 66h
|
retlw 66h
|
||||||
retlw 6Dh
|
retlw 6Dh
|
||||||
retlw 7Dh
|
retlw 7Dh
|
||||||
retlw 07h
|
retlw 07h ; siete
|
||||||
retlw 7Fh
|
retlw 7Fh ; ocho
|
||||||
retlw 6Fh ; A
|
retlw 6Fh ; nueve
|
||||||
retlw 77h ; B
|
retlw 77h ; A
|
||||||
retlw 7Ch ; C
|
retlw 7Ch ; B
|
||||||
retlw 39h ; D
|
retlw 39h ; C
|
||||||
retlw 5Eh ; E
|
retlw 5Eh ; D
|
||||||
|
retlw 79h ; E
|
||||||
retlw 71h ; F
|
retlw 71h ; F
|
||||||
|
|
||||||
|
|
||||||
; Delay subroutine (approx 500ms)
|
; Delay subroutine (approx 500ms)
|
||||||
Delay:
|
Delay:
|
||||||
MOVLW D'250' ; Outer loop count
|
MOVLW D'250' ; Outer loop count
|
||||||
|
|
@ -194,28 +211,50 @@ Delay_Outer:
|
||||||
Delay_Inner:
|
Delay_Inner:
|
||||||
NOP ; Do nothing (No Operation)
|
NOP ; Do nothing (No Operation)
|
||||||
NOP
|
NOP
|
||||||
NOP
|
|
||||||
NOP
|
|
||||||
DECFSZ R2, F ; Decrement inner loop counter
|
DECFSZ R2, F ; Decrement inner loop counter
|
||||||
GOTO Delay_Inner ; Repeat inner loop
|
GOTO Delay_Inner ; Repeat inner loop
|
||||||
;; Multiplex code
|
;; Multiplex code
|
||||||
clrf PORTD
|
call display
|
||||||
movlw 0x04
|
|
||||||
movwf PORTE
|
|
||||||
movff DISP0, TEMP
|
|
||||||
call sevensw
|
|
||||||
movwf PORTD
|
|
||||||
call disp_delay
|
|
||||||
clrf PORTD
|
|
||||||
movlw 0x02
|
|
||||||
movwf PORTE
|
|
||||||
movff DISP1, TEMP
|
|
||||||
call sevensw
|
|
||||||
movwf PORTD
|
|
||||||
|
|
||||||
DECFSZ R1, F ; Decrement outer loop counter
|
DECFSZ R1, F ; Decrement outer loop counter
|
||||||
GOTO Delay_Outer ; Repeat outer loop
|
GOTO Delay_Outer ; Repeat outer loop
|
||||||
RETURN ; Return from delay
|
RETURN ; Return from delay
|
||||||
|
|
||||||
|
display:
|
||||||
|
clrf PORTD
|
||||||
|
movff DISP0, TEMP
|
||||||
|
call sevensw
|
||||||
|
movwf PORTD
|
||||||
|
movlw 0x04
|
||||||
|
movwf PORTE
|
||||||
|
call disp_delay
|
||||||
|
|
||||||
|
clrf PORTD
|
||||||
|
movff DISP1, TEMP
|
||||||
|
call sevensw
|
||||||
|
movwf PORTD
|
||||||
|
movlw 0x02
|
||||||
|
movwf PORTE
|
||||||
|
call disp_delay
|
||||||
|
|
||||||
|
clrf PORTD
|
||||||
|
movff DISP2, TEMP
|
||||||
|
call sevensw
|
||||||
|
movwf PORTD
|
||||||
|
movlw 0x01
|
||||||
|
movwf PORTE
|
||||||
|
call disp_delay
|
||||||
|
|
||||||
|
clrf PORTD
|
||||||
|
clrf PORTE
|
||||||
|
movff DISP3, TEMP
|
||||||
|
call sevensw
|
||||||
|
movwf PORTD
|
||||||
|
movlw 0x10
|
||||||
|
movwf PORTA
|
||||||
|
call disp_delay
|
||||||
|
clrf PORTA
|
||||||
|
return
|
||||||
|
|
||||||
END ; End of program
|
END ; End of program
|
||||||
;todopic y aquihayapuntes
|
;todopic y aquihayapuntes
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user