![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| I'm having trouble in MPLab Sim. I've written a small program to see if I have grasped some of the theory behind the programming language. Everytime I try to debug/simulate it, it gives the error: "CORE-E0002: Stack under flow error occurred from instruction at 0x000005". Can someone look at the program and see where I'm messing up? I've got it assigned to program a 16F628A. I've got the watch window open and viewing the data on PORTA, and that's really all that the program is supposed to do is make the PORTA data go 0000 > 0001 > 0011 then repeat. Thanks, Joe ;************************************************* ********************* ; * ; Files required: * ; 16F628A.lkr * ; * ; * ;************************************************* ********************* list p=16F628A ; list directive to define processor #include <p16F628A.inc> ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file __CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT ;***** VARIABLE DEFINITIONS (examples) PORTA EQU 05h TRISA EQU 85h ;************************************************* ********************* MAIN CODE main ;******SETUP PORTA****** BSF STATUS, 5 MOVLW 00H MOVWF TRISA BCF STATUS, 5 START BSF PORTA, 0 BSF PORTA, 1 BSF PORTA, 2 MOVLW 00h MOVWF PORTA GOTO START END ; directive 'end of program' | |
| |
| | (permalink) |
| You forgot to include an Code: org 0x000 Also no need to redefine the PORTA & TRISA, your include file does that for you. Last edited by blueroomelectronics; 21st November 2007 at 06:10 PM. | |
| |
| | (permalink) | ||
| Quote:
Quote:
| |||
| |
| | (permalink) | |
| Quote:
disregard the last post. I got it to working now. Thanks for the help! | ||
| |
| | (permalink) |
| Put a comment ; in front of the words "MAIN CODE" or remove it. This is being treated as a code command by the linker. You have the org statment in the wrong place. It should be on line above the word "main" for this example. You don't need to compile with the linker - that is for re-locatable code. | |
| |
| | (permalink) | |
| Quote:
You should not change one bit in a port on the line after you have changed another line. The reason is that each instruction reads the port, modifies one bit, and writes all 8 bits back to the port. The voltage on the port is read only about 1 oscillator cycle after it has been set. If there is some small capacitance on the port, the voltage will not have been established, and the second instruction will read porta, 1 as low so it will be written as low just as porta, 2 goes high. | ||
| |
| | (permalink) | ||
| Quote:
I'm new to the MPLab software so I probably sound green behind the ear to some of you more knowledgeable people. Quote:
| |||
| |
| | (permalink) |
| Back to back bit changing is fine in any register except a port. | |
| |
| | (permalink) |
| Works fine. Code: list p=16F628A
include <p16F628A.inc>
errorlevel -302
__CONFIG _LVP_OFF & _WDT_OFF & _INTOSC_OSC_NOCLKOUT
MAIN
;******SETUP PORTA******
BSF STATUS, RP0
clrf TRISA
BCF STATUS, RP0
START BSF PORTA, 0
BSF PORTA, 1
BSF PORTA, 2
clrf PORTA
GOTO START
END | |
| |
| | (permalink) | |
| Quote:
To remove the linker script, click on "project" "remove file from project" then click on the "16f628a.lkr" file to remove it. | ||
| |
| | (permalink) |
| thanks. Removing the linker file fixed the error I was receiving. Whenever I'm in the watch mode watching the PORTA, it doesn't change the values as I single step through it using the debugger. Any ideas on what may be causing that? The values of TRISA change from FF to 20 though. But PORTA never changes values? | |
| |
| | (permalink) | |
| Quote:
Code: main
movlw 0x07
movwf CMCON | ||
| |
| | (permalink) | |
| Quote:
WHOO HOO! It's working! Thanks everyone for the help! | ||
| |
| | (permalink) |
| list p=16f84a ; initialize to the correct PIC type #include <p16f84a.Inc> errorlevel -302 org 0x0000 ;Reset vector Bsf 03h,5 Movlw 01h Movwf 85h Bcf 03h,5 end I ALSO GOT THE SAME Error "CORE-E0002: Stack under flow error occurred from instruction at 0x000005" can anyone help me pls? | |
| |
| | (permalink) |
| I think that the problem is what your program does after it has executed all your code. You haven't got a goto at the end to make it loop somewhere, and line 0x000005 is after the 4 lines of code in your example. Most programs have an initialise that runs once, then a loop that cycles forever after that. There a a couple of ways you could make things easier for yourself. 1) Use a pic16F627a. It is newer, better and cheaper than a pic16F84A 2) Use the names of registers and bits. It makes code easier to read. That is why you have the include file. The geeks and anoraks (http://en.wikipedia.org/wiki/Anorak_%28slang%29) here will know that:- Bsf 03h,5 means Bsf status, rp0 which sets the banking bit to page 1, but there is no point making it more difficult to read. Similarly, 85h is the TRISA register (short for Tri-state, port A) and it is easier to refer to it as that. | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| Question about Inchworm+ | Quan | Micro Controllers | 54 | 28th October 2007 01:21 AM |
| Debugging 877A with MPLAB | williB | Micro Controllers | 10 | 7th May 2007 04:53 PM |
| Need help badly on Inchworm and MPLAB | thushy | Micro Controllers | 14 | 11th March 2007 07:05 PM |
| Inchworm project started | williB | Micro Controllers | 69 | 5th March 2007 07:56 PM |
| MPLAB SIM ERROR | gastonanthony | Micro Controllers | 7 | 28th April 2005 06:03 PM |