SkeeterB08
Newbie level 6
- Joined
- Sep 1, 2008
- Messages
- 14
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- NorthEast Mississippi, USA
- Activity points
- 1,397
Program Stack Overflow
can anyone help me? I've got a problem with the code I'm working on. For a while it was kicking out of the program when RA0 and RA1 were both low. I've played with it and now when RA0 and RA1 are low, it runs a bit then gives me a stack overflow error on Pic Simulator IDE. Where am I going wrong?? Oh, and that bit at the beginning with errorlevel throws me out when compiling, so I have it commented out.
Here is the Logic diagram of my circuit
(Operation)
Upper (RA0) + Lower Sensor (RA1) = 1 Then Operation (RB6) = 1; Warn (RB5) = 0; Refill (RB3, RB4) = 0
Upper Sensor = 0 + Lower Sensor = 1 Then Operation = 1; Warn = 1; Refill = 0
(Refilling)
Upper + Lower Sensor = 0 Then Operation = 0; Warn = Flashing; Refill = 1
If Upper Sensor = 0 Then Operation = 0, Warn = Flashing, Refill = 1
If Upper Sensor = 1 Then Operation = 1; Warn = 0; Refill = 0
(End Refilling)
Here's the code as it stands. Its for the PIC16F628
[/img]
can anyone help me? I've got a problem with the code I'm working on. For a while it was kicking out of the program when RA0 and RA1 were both low. I've played with it and now when RA0 and RA1 are low, it runs a bit then gives me a stack overflow error on Pic Simulator IDE. Where am I going wrong?? Oh, and that bit at the beginning with errorlevel throws me out when compiling, so I have it commented out.
Here is the Logic diagram of my circuit
(Operation)
Upper (RA0) + Lower Sensor (RA1) = 1 Then Operation (RB6) = 1; Warn (RB5) = 0; Refill (RB3, RB4) = 0
Upper Sensor = 0 + Lower Sensor = 1 Then Operation = 1; Warn = 1; Refill = 0
(Refilling)
Upper + Lower Sensor = 0 Then Operation = 0; Warn = Flashing; Refill = 1
If Upper Sensor = 0 Then Operation = 0, Warn = Flashing, Refill = 1
If Upper Sensor = 1 Then Operation = 1; Warn = 0; Refill = 0
(End Refilling)
Here's the code as it stands. Its for the PIC16F628
Code:
list p=16f628 ; list directive to define processor
#include <p16f628.inc> ; processor specific variable definitions
; errorlevel -302 ;hide banking message
;*****
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF
;*****
;internal osc settings
;*****
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
w_temp EQU 0x70 ; variable used for context saving
status_temp EQU 0x71 ; variable used for context saving
Count1 EQU 0X72 ; First Counter for Delay Loops
Count2 EQU 0X73 ; Second Counter for Delay Loops
;**********************************************************************
ORG 0x000 ; processor reset vector
goto Start ; go to beginning of program
;*****
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
;*****
Start
clrf PORTA
clrf PORTB
MOVLW B'00000111'
MOVWF CMCON ; Turn off comparator
bsf STATUS,RP0 ; bank one
movlw 0xFF
movwf PORTA ; porta all Input
movlw 0x00
movwf PORTB ; portb all Output
bcf STATUS,RP0 ; return to bank 0
;*****
movlw b'00000000' ;See datasheet for prefered
movwf OPTION_REG ;settings of OPTION_REG
bsf PORTB,7 ; Turn on Power LED
btfss PORTA,0 ; Check if Upper Sensor = 1
Goto Prestart ; If not go to prestart subroutine
bsf PORTB,6
Goto Run
;*****
Prestart
bsf PORTB,5 ; Turn on Warning LED
bsf PORTB,4 ; Turn on Refill LED
bsf PORTB,3 ; Turn On Relay Sub-Circuit
btfsc PORTA,0 ; If Upper Sensor = 1
Goto Run ; Go to Operation Mode
Run
btfss PORTA,0 ; If Upper Sensor = 0
bsf PORTB,5 ; Then turn on Warning LED
btfsc PORTA,0 ; If Upper Sensor = 1
decfsz Count1,1 ; Don't Decrement Counter 1
btfss PORTA,1 ; If Lower Sensor = 0
call Refill ; Go To Refill Subroutine
btfsc PORTA,1 ; If Lower Sensor = 0
decfsz Count2,1 ; Don't Decrement Counter2
goto Run
Refill
bsf PORTB,4 ; Turn on Refill LED
bsf PORTB,3 ; Turn on Refill Sub-Circuit
btfsc PORTA,0 ; If Upper Sensor = 1
bcf PORTB,3 ; Turn Off Refill Sub-Circuit
btfsc PORTA,0 ; If Upper Sensor = 1
bcf PORTB,4 ; Turn off Refill LED
btfsc PORTA,0 ; If Upper Sensor = 1
bcf PORTB,5 ; Turn off Warning LED
bsf PORTB,6
goto Run
;*****
END