I'm currently working on a countdown timer project.I used PIC18F452 microcontroller for my project. I compiled the code in mplab and it has succesfully been builtHowever in proteus, the countdown timer seems to be working until a certain point and then it will reset. In the simulation, it said that the stack overflow is forcing the device to reset.
And here is the code:`
#include<p18f452.inc>
radix dec
bin set 0x00
bcdH set 0x01
MINUTE set 0x03
SECOND set 0x04
FXMin set 0x06
FXSec set 0x07
START set 0x08
org 0x00
goto init
org 0x08
goto interrupt
org 0x18
goto interrupt
init movlw 0x07
movwf ADCON1
setf TRISB
clrf TRISC
clrf TRISD
;setting interrupt
bcf INTCON, INT0IF
bsf INTCON, INT0IE
bcf INTCON3, INT1IF
bsf INTCON3, INT1IE
bcf INTCON3, INT2IF
bsf INTCON3, INT2IE
bsf INTCON3, INT2IP
;filling TMR0 value
movlw 0x06
movwf T0CON
movlw 0x67
movwf TMR0H
movlw 0x68
movwf TMR0L
bcf INTCON, TMR0IF
bsf INTCON, TMR0IE
bsf INTCON2, TMR0IP
bsf RCON, IPEN
clrf PORTB
clrf PORTC
clrf PORTD
clrf CCP1CON
bsf T0CON, TMR0ON
loop bsf INTCON, GIE
bsf INTCON, GIEL
bsf INTCON, GIEH
show movff FXMin, PORTD
movff FXSec, PORTC
bra loop
interrupt btfsc INTCON, INT0IF
bra int00
btfsc INTCON3, INT1IF
bra int01
btfsc INTCON3, INT2IF
bra int02
checkstart btfsc INTCON, TMR0IF
bra inttmr0
exit retfie
int00 bcf INTCON, INT0IF
incf MINUTE
movlw 60
cpfseq MINUTE
bra calcBCD
clrf MINUTE
bra calcBCD
int01 bcf INTCON,INT1IF
setf START
bra checkstart
int02 bcf INTCON3,INT2IF
clrf MINUTE
clrf SECOND
clrf FXMin
clrf FXSec
clrf START
bra calcBCD
inttmr0 bcf INTCON, TMR0IF
movlw 0x06 ;0x47
movwf T0CON
movlw 0x90 ;0x00
movwf TMR0H
movlw 0x00
movwf TMR0L
bsf T0CON, TMR0ON
movlw 0xFF
cpfseq START
bra calcBCD
bra COUNTDOWNLOOP
COUNTDOWNLOOP nop
CHECK movlw 0x00
cpfseq SECOND
bra DECSEC
bra CHECKMIN
DECSEC decf SECOND
bra calcBCD
CHECKMIN movlw 0x00
cpfseq MINUTE
bra DECMIN
bra calcBCD;
DECMIN decf MINUTE
movlw 60
movwf SECOND
bra DECSEC
calcBCD movff MINUTE, bin
call bin2bcd
movwf FXMin
movff SECOND, bin
call bin2bcd
movwf FXSec
bra show
retfie
bin2bcd clrf WREG
clrf bcdH
bsf bcdH,0
bcd_lp rlcf bin
addwfc WREG
daw
rlcf bcdH
bnc bcd_lp
return
return
end
`