CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Why does my PIC skip GOTO ? What could be wrong ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nurquhar



Joined: 05 Aug 2006
Posts: 149
Location: Redditch, UK

View user's profile Send private message Visit poster's website

Why does my PIC skip GOTO ? What could be wrong ?
PostPosted: Tue Aug 08, 2006 2:54 am     Reply with quote

I have some simple code that the complier (V3.249) is generating GOTO's to implement (even though I have used #separate for the function call!). The source code and assembley below.

I am using Microchip ICD2 to trace the code on a PIC16F648_ICD chip plugged into may target.

If I set a breakpoint on a NOP before or after the check_rx() and run the traget it will halt at the expected instruction. If I move the break point to the NOP at the begining of the check_rx() function and run the traget from the beginning again then the break point is never reached !!

What is realy unexplainable is if I single step (step into) through this bit of code in main()

0460: NOP
.................... nop() ;
0461: NOP
.................... check_rx() ;
0462: GOTO 3B7
.................... nop() ;
0463: NOP

then it never does the GOTO 3B7 it just steps to the next NOP at 0463.

If I carry on single stepping it also fails to do the GOTO 45F and effectivley exits the while(1) {} loop, it runs through the GOTO at the end of main loop also, ie its crashed !!

0463: NOP
.................... nop() ;
0464: NOP
.................... nop() ;
0465: NOP
.................... }
0466: GOTO 45F
....................


The source ..........................................................
..................................

#separate
void check_rx()
{
char ch ;

nop() ;
nop() ;
nop() ;

// Check for overrun error
if (OERR) {
// Clear the error
CREN = 0 ;
CREN = 1 ;
mstcp_rawin(0, MSTCP_OVERRUN_ERR) ;
}

nop() ;
nop() ;
nop() ;

// Check for framing error
if (FERR) { \
ch=RCREG ;
mstcp_rawin(ch, MSTCP_FRAME_ERR) ;
}

nop() ;
nop() ;
nop() ;

// Check for command
if(kbhit()) {
ch = getc() ;
mstcp_rawin(ch, MSTCP_DATA_RX) ;
}

nop() ;
nop() ;
nop() ;
}
.

.
main()
{
.
.
.

while(1) {
nop() ;
nop() ;
nop() ;
check_rx() ;
nop() ;
nop() ;
nop() ;
}


......................................................................................................
.........................................................................
The relavant snippets are from the LST file are :

CCS PCM C Compiler, Version 3.249, 33800 08-Aug-06 08:57

Filename: LinLED_01.lst

ROM used: 1137 words (30%)
Largest free fragment is 1792
RAM used: 63 (38%) at main() level
89 (53%) worst case
Stack: 6 worst case (5 in main + 1 for interrupts)

*
0000: NOP
0001: MOVLW 00
0002: MOVWF 0A
0003: GOTO 3E0

.
.

....................
....................
.................... #separate
.................... void check_rx()
.................... {
.................... char ch ;
....................
.................... nop() ;
*
03B7: NOP
.................... nop() ;
03B8: NOP
.................... nop() ;
03B9: NOP
....................
.................... // Check for overrun error
.................... if (OERR) {
03BA: BTFSS 18.1
03BB: GOTO 3C2
.................... // Clear the error
.................... CREN = 0 ;
03BC: BCF 18.4
.................... CREN = 1 ;
03BD: BSF 18.4
.................... mstcp_rawin(0, MSTCP_OVERRUN_ERR) ;
03BE: CLRF 5E
03BF: MOVLW 87
03C0: MOVWF 5F
03C1: CALL 238
.................... }
....................
.................... nop() ;
03C2: NOP
.................... nop() ;
03C3: NOP
.................... nop() ;
03C4: NOP
....................
.................... // Check for framing error
.................... if (FERR) { \
03C5: BTFSS 18.2
03C6: GOTO 3CE
.................... ch=RCREG ;
03C7: MOVF 1A,W
03C8: MOVWF 5D
.................... mstcp_rawin(ch, MSTCP_FRAME_ERR) ;
03C9: MOVF 5D,W
03CA: MOVWF 5E
03CB: MOVLW 86
03CC: MOVWF 5F
03CD: CALL 238
.................... }
....................
.................... nop() ;
03CE: NOP
.................... nop() ;
03CF: NOP
.................... nop() ;
03D0: NOP
....................
.................... // Check for command
.................... if(kbhit()) {
03D1: BTFSS 0C.5
03D2: GOTO 3DB
.................... ch = getc() ;
03D3: BTFSS 0C.5
03D4: GOTO 3D3
03D5: MOVF 1A,W
03D6: MOVWF 5D
.................... mstcp_rawin(ch, MSTCP_DATA_RX) ;
03D7: MOVF 5D,W
03D8: MOVWF 5E
03D9: CLRF 5F
03DA: CALL 238
.................... }
....................
.................... nop() ;
03DB: NOP
.................... nop() ;
03DC: NOP
.................... nop() ;
03DD: NOP
.................... }
03DE: BCF 0A.3
03DF: GOTO 463 (RETURN)
....................

.
.

....................
.................... while(1) {
.................... nop() ;
045F: NOP
.................... nop() ;
0460: NOP
.................... nop() ;
0461: NOP
.................... check_rx() ;
0462: GOTO 3B7
.................... nop() ;
0463: NOP
.................... nop() ;
0464: NOP
.................... nop() ;
0465: NOP
.................... }
0466: GOTO 45F
....................
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 08, 2006 12:33 pm     Reply with quote

You should ask this question in the Microchip ICD2 forum.
It might be some issue with the 16F648A-ICD header.
http://forum.microchip.com/tt.aspx?forumid=49
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group