I'm making a code for PIC18F4520 stopwatch using a single 7 segment LED and 8 buttons. Button 1 to stop and button 2 to reset. The following is my code.
LIST p=18F4520
#include <P18F4520.INC>
CONFIG OSC = XT
CONFIG WDT = OFF
CONFIG LVP = OFF
CBLOCK 0x000
DELAY_H
DELAY_L
DELAY_U
input
endc
ORG 0x0000
goto Main
ORG 0x0800
BTFSC INTCON,INT0IF
call INT0_ISR
BTFSC INTCON3,INT1IF
call INT1_ISR
RETFIE
ORG 0x0100
Main
movlw 0x0F
movwf ADCON1
clrf TRISD
clrf PORTD
setf TRISB
BCF INTCON,INT0IF
BSF INTCON,INT0IE
BCF INTCON2,INTEDG0
BCF INTCON3,INT1IF
BSF INTCON3,INT1IE
BCF INTCON2,INTEDG1
BSF INTCON,GIE
movlw 0x00
movwf input
call bcd_7seg
movwf PORTD
count equ 0x25
movlw 0x0A
movwf count
sec
incf input, F
call bcd_7seg
movwf PORTD
call Delay
decf count, F
bnz sec
goto count
bcd_table:
db 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x3F
bcd_7seg:
movlw low bcd_table
movwf TBLPTRL
movlw high bcd_table
movwf TBLPTRH
movlw upper bcd_table
movwf TBLPTRU
movf input, W
addwf TBLPTRL, F
movlw 0
addwfc TBLPTRH
addwfc TBLPTRU
TBLRD*
movf TABLAT, W
RETURN
Delay:
MOVLW d'10'
MOVWF DELAY_U
LOP1_0:
MOVLW 0x80
MOVWF DELAY_H
LOP1_1:
MOVLW 0xFF
MOVWF DELAY_L
LOP1_2:
DECF DELAY_L, F
BNZ LOP1_2
DECF DELAY_H, F
BNZ LOP1_1
DECF DELAY_U, F
BNZ LOP1_0
return
INT0_ISR : ?
INT1_ISR : ?
delay:
MOVLW D'100'
MOVWF 1
back
MOVLW D'0'
MOVWF 2
here
NOP
NOP
NOP
NOP
NOP
NOP
decf 2, F
BNZ here
decf 1, F
BNZ back
return
end
Even though I didn't put any instructions in INT0_ISR and INT1_ISR, both button1 and button changes the number on LED to 1. What instructions should I put in INT0_ISR and INT1_ISR to give out the correct result? Thank you for your help!