PDA

View Full Version : Help with assembly programming please - Stack Underflow



Megahertz
- 9th August 2012, 19:03
I am not an expert in assembly language so can someone help me please in solving this problem. I am simulating currently in proteus and having stack underflow error when button on PortA.0 is pressed/pulled low. The second error is for writing data to EEPROM location 0. The error says CPD bit in configuration word is not set.

My configuration word in my code is :

__Config _XT_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _BODEN & _CP & _CPD


The following is my ISR routine.

PIC->16F676

There are 4 output pins, PortC.0/3/4/5. The ISR routine is suppose to check if Button on PortA.0 is pressed then if all outputs are low then pull all of them high and if any one of them is high, then pull all of them low and wait for the button to be released. Also write the action taken on the outputs to the eeprom.

The code is also incrementing 4 byte size variables i,j,k,l to reach the value stored in p (which is 150). ISR is for TIMER0 interrupt only.


ISR:
asm
;CONTEXT SAVING CODE HERE

T0Overflow
btfss INTCON, T0IF ; check if timer overflow flag
Goto EndInt

; PBP version
; if i<p then i=i+1
; if j<p then j=j+1
; if k<p then k=k+1
; if L<p then L=L+1

movlw _i
bcf STATUS,Z
xorwf _p,w ; p is a PBP variable and a constant with value 150. (P CON 150)
btfss STATUS,Z
incf _i

movlw _j
bcf STATUS,Z
xorwf _p,w
btfss STATUS,Z
incf _j

movlw _k
bcf STATUS,Z
xorwf _p,w
btfss STATUS,Z
incf _k

movlw _l
bcf STATUS,Z
xorwf _p,w
btfss STATUS,Z
incf _l

btfsc PORTA,0 ; Button Pressed?
Goto Finish

btfsc PORTC,0
Goto Putlow ; If it is high then pull all outputs low, goto Pull Low
btfsc PORTC,3
Goto Putlow
btfsc PORTC,4
Goto Putlow
btfsc PORTC,5
Goto Putlow

; If none is high then put all outputs high
bsf PORTC,0
bsf PORTC,3
bsf PORTC,4
bsf PORTC,5

; Writing above states to EEPROM

bsf STATUS,RP0 ; Jump tp BANK1

clrf EEADR
movlw 1
movwf EEDATA
Call SaveVal

movlw 1
movwf EEADR
movwf EEDATA
Call SaveVal

movlw 2
movwf EEADR
movlw 1
movwf EEDATA
Call SaveVal

movlw 3
movwf EEADR
movlw 1
movwf EEDATA
Call SaveVal

bcf STATUS,RP0 ; Jump to BANK0
Goto Skipp

; PBP version
; If Sw1=0 then
; if (PortC.0=0) then
; if (PortC.3=0) then
; if (PortC.4=0) then
; if (PortC.5=0) then
; High rel1 : High rel2 : High rel3 : High rel4
; write 0,1 : write 1,1 : write 2,1 : Write 3,1
; goto skipp
; endif
; endif
; endif
; endif
; Low Rel1 : Low Rel2 : Low Rel3 : Low Rel4
; write 0,0 : write 1,0 : write 2,0 : write 3,0
; Endif
;skipp:
; While PortA.0=0 : Pause 50 : Wend


SaveVal
bsf EECON1,WREN
bcf INTCON,GIE
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1,WR
btfsc EECON1,WR
Goto $-1
bsf INTCON,GIE
RETURN

Putlow
bcf PORTC,0
bcf PORTC,3
bcf PORTC,4
bcf PORTC,5

; Writing above states to EEPROM

bsf STATUS,RP0
clrf EEADR ; set eeprom address location - 0 in this case
clrf EEDATA ; fill data in this register - 0 in this case
Call SaveVal ; save it

movlw 1
movwf EEADR
clrf EEDATA
Call SaveVal

movlw 2
movwf EEADR
clrf EEDATA
Call SaveVal

movlw 3
movwf EEADR
clrf EEDATA
Call SaveVal

bcf STATUS,RP0

Skipp
btfss PORTA,0 ; button released?
GOTO Skipp

Finish
bcf INTCON,T0IF
clrf TMR0

EndInt
CONTEXT RESTORE CODE
endasm

(Screenshot of errors)
6626