added clock counter

This commit is contained in:
Fernando 2025-02-25 10:50:25 -06:00
parent d4a38ac95f
commit 96bee98513

View File

@ -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 WDT = OFF ; Watchdog Timer 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
ORG 0x00 ; Program starts at address 0
ROTA1 EQU 0x01
ROTA2 EQU 0x02
ROTA3 EQU 0x04
@ -18,13 +18,18 @@ R1 EQU 0x020
R2 EQU 0x021
R3 EQU 0x024
CUENTA EQU 0x022
CUENTA2 EQU 0x034
TEMP EQU 0x23
DISP0 EQU 0x30
DISP1 EQU 0x31
DISP2 EQU 0x32
DISP3 EQU 0x33
ORG 0x0000
goto Start
ORG 0x0008
goto loop
Start:
; Initialize PORTB
@ -32,37 +37,43 @@ Start:
CLRF LATD ; Clear PORTB outputs
CLRF LATB
BCF INTCON2, 7
BCF INTCON2, RBPU
MOVLW 0xff
MOVWF TRISB ; set port b to input
movlw 0x0f
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 TRISE
clrf CUENTA
clrf CUENTA2
loop:
;movlw 0x17
;movwf CUENTA
;call Delay
;call sevensw
;movwf PORTD
;goto loop
movf PORTB, W
bcf INTCON, RBIF
clrf CUENTA
call splitDigit
call Delay
movf PORTB, W
xorlw ROTA1
btfsc STATUS, Z
goto leftright
goto hexa ; cuenta 1
xorlw ROTA2^ROTA1
btfsc STATUS, Z
goto right
goto decimal ; cuenta 2
xorlw ROTA2^ROTA3
btfsc STATUS, Z
goto left
goto des ; cuenta 3 wip
xorlw ROTA3^ROTA4
btfsc STATUS, Z
goto alternate
@ -74,74 +85,66 @@ loop:
goto outcenter
goto loop
leftright:
CALL Delay ; Delay
RLCF PORTD, f
BTFSS STATUS,0
GOTO leftright ; Repeat the loop
lright:
CALL Delay ; Delay
RRCF PORTD, F
BTFSS STATUS,0
GOTO lright ; Repeat the loop
return
hexa:
call splitDigit
call Delay
incf CUENTA, F
call Delay
goto hexa
left:
MOVLW 0x80
MOVWF PORTD
rl: CALL Delay ; Delay
RRCF PORTD, F
BTFSS STATUS,0
GOTO rl ; Repeat the loop
return
right:
des:
clrf CUENTA
clrf CUENTA2
rl:
call splitDigit
call Delay
incf CUENTA, W
daw
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 Delay
CALL Delay
goto right
incf CUENTA, W
daw
movwf CUENTA
Call Delay
goto decimal
alternate:
movlw 0xaa
movwf PORTD
movlw 0xff
movwf CUENTA
call splitDigit
call Delay
movlw 0x55
movwf PORTD
rl2:
call splitDigit
call Delay
return
decfsz CUENTA
goto rl2
goto alternate
centerout:
movlw 0x18
movwf PORTD
call Delay
movlw 0x24
movwf PORTD
call Delay
movlw 0x42
movwf PORTD
call Delay
movlw 0x81
movwf PORTD
call Delay
centerout: ;; clock
return
outcenter:
movlw 0x81
movwf PORTD
call splitDigit
call Delay
movlw 0x42
movwf PORTD
call Delay
movlw 0x24
movwf PORTD
call Delay
movlw 0x18
movwf PORTD
call Delay
return
incf CUENTA, W
daw
movwf CUENTA
Call Delay
goto decimal
splitDigit:
movf CUENTA, W
@ -150,12 +153,20 @@ splitDigit:
swapf CUENTA, W
andlw 0x0f
movwf DISP1
movf CUENTA2, W
andlw 0x0f
movwf DISP2
swapf CUENTA2, W
andlw 0x0f
movwf DISP3
return
disp_delay:
movlw D'250'
movwf R3
disp_delay_inner:
NOP
NOP
NOP
NOP
decfsz R3, F
@ -163,11 +174,15 @@ disp_delay_inner:
return
sevensw:
movlw high(sevensw)
movlw high(sevenjmp)
movwf PCLATH
movf TEMP, W
addwf TEMP, W
addwf PCL, F
addlw low(sevenjmp)
btfsc STATUS, 0
incf PCLATH, 1
movwf PCL
sevenjmp:
retlw 3Fh
retlw 06h
retlw 5Bh
@ -175,15 +190,17 @@ sevensw:
retlw 66h
retlw 6Dh
retlw 7Dh
retlw 07h
retlw 7Fh
retlw 6Fh ; A
retlw 77h ; B
retlw 7Ch ; C
retlw 39h ; D
retlw 5Eh ; E
retlw 07h ; siete
retlw 7Fh ; ocho
retlw 6Fh ; nueve
retlw 77h ; A
retlw 7Ch ; B
retlw 39h ; C
retlw 5Eh ; D
retlw 79h ; E
retlw 71h ; F
; Delay subroutine (approx 500ms)
Delay:
MOVLW D'250' ; Outer loop count
@ -194,28 +211,50 @@ Delay_Outer:
Delay_Inner:
NOP ; Do nothing (No Operation)
NOP
NOP
NOP
DECFSZ R2, F ; Decrement inner loop counter
GOTO Delay_Inner ; Repeat inner loop
;; Multiplex code
clrf PORTD
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
call display
DECFSZ R1, F ; Decrement outer loop counter
GOTO Delay_Outer ; Repeat outer loop
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
;todopic y aquihayapuntes