Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 13th July 2007, 09:30 PM   #1
Default mplab ASM not following calls properly

Please consider the following code:
Code:
INCLUDE "P16F627A.INC"
LIST P=16F627A


__Config _INTOSC_OSC_NOCLKOUT & _DATA_CP_OFF & _CP_OFF  &_LVP_OFF &_BOREN_ON    & _MCLRE_OFF    & _WDT_OFF & _PWRTE_OFF 

cblock    0x20
    SDelayCount    
endc

org 0
poweron


    BSF        STATUS,RP0     ;MOVE TO BANK1
    CLRF    TRISB        ;PORT B ALL OUTPUTS
    CLRF    TRISA        ;PORT a ALL OUTPUTS, EXCLUDING A5 OBVIOUSLY
    BCF        STATUS, RP0 ;MOVE TO BANK0

    CLRF    PORTA
    MOVLW 0x07 ;Turn comparators off and
    MOVWF CMCON ;enable pins for I/O

again
    MOVLW    0xff
    movwf    PORTA
    MOVLW    0
    MOVWF    PORTB

    call     ShortDelay
    
    MOVLW    0x00
    movwf    PORTA
    MOVLW    0
    MOVWF    PORTB
    call     ShortDelay
    
goto again


ShortDelay      

MOVLW    H'40'        ;Get current selected multiplex rate
        MOVWF    SDelayCount        ;Store desired delay count
SDelayLoop

    NOP
        NOP
        NOP
        NOP
        DECFSZ    SDelayCount
        GOTO    SDelayLoop
        retlw    0


END
Im simulating in MPLAB.

For some reason when the ShortDelay is called
the PCL is set to the correct position(i.e MOVLW instruction), but the next time i press step into, the executing line skips to SDelayLoop.
if i press step into again, PCL Jumps away from my code to an undefined bit of memory (PCL reads Decimal:119).
My shortDelay code is never executed, and the microcontroller is no longer running any of my code!

Does anyone know whats happening here?

Many thanks
bitem2k is offline  
Old 13th July 2007, 10:55 PM   #2
Default

Quote:
Originally Posted by bitem2k
Does anyone know whats happening here?
I've just simulated your program and 'shortDelay' is executed as you would expect. It requires 453 cycles including 'call'.
So no, I don't know what's wrong with your simulation.
eng1 is offline  
Old 13th July 2007, 11:38 PM   #3
Default

Ah, so something wrong with mplab.
thanks mate, perhaps time to try and reinstall.
bitem2k is offline  
Old 14th July 2007, 11:59 AM   #4
Default

Be sure to step into and not over.
donniedj is offline  
Old 14th July 2007, 03:09 PM   #5
Default

The only time I have seen this happen is when I have stepped through code that has been changed but not been recompiled.

Mike.
Pommie is online now  
Old 24th July 2007, 12:45 PM   #6
Default

I believe that its somthing to do with an incompatability between mplab and vs.net 2005!

I shall email microchip.
bitem2k is offline  
Old 24th July 2007, 01:28 PM   #7
Default

Quote:
Originally Posted by bitem2k
I believe that its somthing to do with an incompatability between mplab and vs.net 2005!
I may regret this?, but what's vs.net 2005 got to do with it?.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 24th July 2007, 10:03 PM   #8
Default

I do alot of programming in C#, so im obviously running MPLAB and VS.net 2005 on the same machine (sometimes at the same time).

Im experiencing wierd problems trying to build tried and tested code in MPLAB.
If i re-install MPLAB, all the problems vanish until the next time I run VS.net.
Then I get build errors the next time I try and assemble code in MPlab.

I have just found a website that says

"
If you are running Visual Studio, then you may or may not know that Visual Studio appears to co-opt the file extension .cod. Apparently, Visual Studio doesn't play well with others, as it won't let other programs that need or use files having that extension...like MPLAB...use it for their own purposes.

* To the best of my observation, computers running Visual Studio will give linker errors when you attempt to build assembly files in MPLAB. The visible symptoms of the problem are error messages that refer to stack underflow or core errors. I will try to get specific error messages, so that you know what you're looking for to see if it's happened.
* The quickest solution (the one that was applied to best effect in the CEL) is to do a clean reinstall of MPLAB. This will make MPLAB work again, at least up to the point where you use Visual Studio to do something. Since no one uses Visual Studio in the CEL, we haven't had the chance to observe whether it attempts to grab the extension again.
* If you use Visual Studio often, you may find the MPLAB problem to be a recurring one. "
bitem2k is offline  
Old 25th July 2007, 01:38 AM   #9
Default

Quote:
Originally Posted by Nigel Goodwin
I may regret this?, but what's vs.net 2005 got to do with it?.
Its a MS application (a.k.a. virus) Nigel, it has everything to do with it.
donniedj is offline  
Old 25th July 2007, 06:22 AM   #10
Default

Does setting the "Suppress Cod-file generation" in "Project>Build Options>project>MPLINK Linker" help.

Mike.
Pommie is online now  
Old 25th July 2007, 08:00 PM   #11
Default

Quote:
Originally Posted by Pommie
Does setting the "Suppress Cod-file generation" in "Project>Build Options>project>MPLINK Linker" help.

Mike.
First thing I looked at!
It turns out that in the latest version, this flag is allready set by default.

Its so annoying! Stupid Micro$oft

Cant say that Microchip are being much help either.

Im going to try running two WINXP users at the same time and using the user switching functionallity of XP. One user will run VS.NET, the other MPLAB.

If it works, the only problem i will then have, is making sure I dont run VS.NET on the MPLAB user account

Cheers.
bitem2k is offline  
Old 27th July 2007, 11:31 AM   #12
Default

It would appear that my workaround works. Its definately easier than re-installing every 5 minutes.
bitem2k is offline  
Reply

Tags
asm, calls, mplab, properly

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Debugging 877A with MPLAB williB Micro Controllers 10 7th May 2007 04:53 PM
Inchworm components gregmcc Micro Controllers 43 18th March 2007 02:37 PM
Need help badly on Inchworm and MPLAB thushy Micro Controllers 14 11th March 2007 07:05 PM
Some Question About Inchworm Ayne Micro Controllers 29 7th March 2007 04:08 AM
Inchworm project started williB Micro Controllers 69 5th March 2007 07:56 PM



All times are GMT. The time now is 05:39 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker