Stack under flow error

Status
Not open for further replies.

krpz

New Member
i try to simulate the code below(mplab sim) but i take this error:

CORE-E0002: Stack under flow error occurred from instruction at 0x000030


i have attached the project code
 
Last edited:
I think that "Call portinit" MUST be a "goto" Then don't return from portint just continue onto main..

Remove "Call main" from the interrupt vector then your good to go.
 
Somewhere you have a return happening without a call. We also need to see your macro.INC and your display.INC files in order to see the entire code.

Also, MPASM already includes a bank select macro, known as "banksel". You use it like this -

Code:
                 banksel            <ADDRESS>

Example, if you want to go to bank 1, you can do -

Code:
                banksel             TRISA

;or

               banksel              0x80

One more thing...you use ORG statements to place code in the lower registers of code ROM -

Code:
                org                   0x0000                         ;reset vector
                goto                  START

Then label the first line of your port init routine "START". There's no reason to can it as a subroutine as you only ever run that segment of code one time.

Lastly, keep your code organized as such -

Code:
<LABEL>                <INSTRUCTION>               <OPERAND>
 
Last edited:
thank all for your advice. They are really helpfull, i write the code from the start and i have no problem as the above.
Thanks again
 
Ok!!! Copy this..

Code:
List p=pic16f877
 include "P16F877.INC"

 __CONFIG _CP_OFF & _WDT_OFF &_BODEN_OFF & _PWRTE_ON & _HS_OSC & _WDT_OFF & _LVP_OFF & _CPD_OFF
 ERRORLEVEL -302
;#####################################################################
;#                         constant definitions                      #
;#####################################################################

#define E_line 0			;from wiring 
#define RS_line 1			;   -//-
#define RW_line 2			;   -//-
#define carry_bit 0			; from datasheet



;######################################################################
;                          variable declaration
;######################################################################
 cblock 0x20
 delay_counter1
 delay_counter2
 temp							;variable store 8-bit data to send to LCD
 GPR1
 key								;variable store key value from keypad
 tmp
 tmp2
 tmp3
 s0								;(s0-s15): 16bytes of state
 s1								;
 s2								;
 s3								;
 s4								
 s5
 s6
 s7
 s8
 s9
 s10
 s11
 s12
 s13
 s14
 s15
 k0								; (k0-k15): 16 bytes of key
 k1
 k2
 k3
 k4
 k5
 k6
 k7
 k8
 k9
 k10
 k11
 k12
 k13
 k14
 k15
 Offset_H
 Offset_L
 sbox
 mixtmp
 mix0
 mix1
 mix2
 mix3
 keytmp0
 keytmp1
 keytmp2
 keytmp3
 rconReg
 rconValue
 rconValue10round
 counter						; counter for AES steps
 rconReg2
 invkeyexpcounter
 endc


;######################################################################
;						register equates
;######################################################################

status equ 0x03
portd equ 0x08
porte equ 0x09
portb equ 0x06
porta equ 0x05
portc equ 0x07
intcon equ 0x0B
;subBytes equ 0x200




 	#include "macro.inc"
 
;org 0h
	org 0h
 	goto port_initialization





;######################################################################
;               PORTS INITIALIZATION
;######################################################################
;WIRING:
;     PortD                 PortE             PortB
; 0 --> lcd bus 0		0 --> lcd RS		0 --> keypad row0
; 1 --> lcd bus 1		1 --> lcd E			1 --> keypad row1
; 2 --> lcd bus 2       2 --> lcd R/W		2 --> keypad row2
; 3 --> lcd bus 3 							3 --> keypad row3
; 4 --> lcd bus 4							4 --> not used
; 5 --> lcd bus 5							5 --> keypad column0
; 6 --> lcd bus 6							6 --> keypad column1
; 7 --> lcd bus 7							7 --> keypad column2
	
port_initialization

		Bank1
		movlw b'00000111'
		movwf TRISB

		movlw b'00001000'
		movwf OPTION_REG

		Bank0
        CLRF    PORTA               ; Initialize PORTA by clearing output data latches
        CLRF    PORTB               ; Initialize PORTB by clearing output data latches
		CLRF 	PORTE
		CLRF	PORTD
       
		Bank1
        MOVLW   0X06        
		MOVWF ADCON1
		MOVLW 0xCF
		MOVWF TRISA

        MOVLW   B'00000000'         ; Value used to initialize data direction
        MOVWF   TRISD               ; Set RB<7:0> as outputs
		MOVWF	TRISE

		Bank0


;######################################################################
;                   MAIN PROGRAMM
;######################################################################

main

 call initializeLCD
 call clearLCD
nop
nop
 call result_in_lcd
nop
nop
 goto stop





stop
	goto stop

 include "display.asm"
end

The include has to be at the end, or the call to your LCD has no return..... Also the " org 0h " must be followed by a goto....
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…