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 support@ccsinfo.com

Compiler puts code out of sequence

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







Compiler puts code out of sequence
PostPosted: Tue Sep 13, 2005 7:14 pm     Reply with quote

I am new to C for PIC's, I have experience with assembly though. I have done a few products with PICs using MPLAB in assembly.

This is the first time I have used CCS C with MPLAB.

I am rewriting assembly code into C for preexisting hardware.

Pretty simple stuff, just a keypad and LCD and a few D I/O lines.

I got the LCD working in C but when I added additional code for the keypad, weird things happened. If I single step through the code all the sudden it branches off into the middle of some other unrelated code.

If I compile and look at the dissasembly view in MPLAB, I can see that the code is fragmented. Here is an exceprt from the dissasembly view that shows where it is acting up. At line 226 there is a gap until line 22A. Line 226 does not have a goto so the program just goes to 227 which is wrong.

Can anyone explain this?

Chris

77: Main()
78: {
00021A 184 CLRF 0x4
00021B 301F MOVLW 0x1f
00021C 583 ANDWF 0x3, F
00021D 1683 BSF 0x3, 0x5
00021E 141F BSF 0x1f, 0
00021F 149F BSF 0x1f, 0x1
000220 151F BSF 0x1f, 0x2
000221 119F BCF 0x1f, 0x3
000222 3007 MOVLW 0x7
000223 09C MOVWF 0x1c
000224 81C MOVF 0x1c, W
000225 1283 BCF 0x3, 0x5
000226 130D BCF 0xd, 0x6
79: //Setup ports and periphials enable interrupt from timer 0
80:
81: SETUP_TIMER_0 (RTCC_DIV_16|RTCC_INTERNAL);
00022A 1683 BSF 0x3, 0x5
00022B 801 MOVF 0x1, W
00022C 39C0 ANDLW 0xc0
00022D 3803 IORLW 0x3
00022E 081 MOVWF 0x1
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 13, 2005 7:51 pm     Reply with quote

This is CCS's answer, from their FAQ:
http://www.ccsinfo.com/faq/?9

Main CCS FAQ page:
http://www.ccsinfo.com/faq/

Also to see all the CCS library code, edit the .H file for your PIC
and comment out the #nolist statement at the top of the file.
Then you will see math routines, etc., in the .LST file.
topfuel
Guest







that does not explain what I am seeing.
PostPosted: Wed Sep 14, 2005 5:30 am     Reply with quote

Thanx for the Faq link.

However I don't think that explains what I am seeing.

The code excerpt that I included shows address 226 as the last sequential line number. What I did not show is that 227 is in the middle of another function. So it goes from main into the middle of a functionl.

How can that be correct?

Chris
Thiago Esteves
Guest







PostPosted: Wed Sep 14, 2005 8:38 am     Reply with quote

Hi Chris,

Post your full code, version compiler, etc and this way
We could help you. But, I think that the next line isn't the
next instruction of your C code, now, the compiler mount
the code of the "best way" that it can.

The Line 227 is in some place of your program with another
instruction, Probability, the C code use this way to call the Lines
Like a "Call" in Assembler, But it call the line without a "Call"
in assembler.

If you still have doubts, post your code and we could help you

Best regards

PS: Sorry By my english

Thiago Cesar
Campinas - São Paulo - Brasil
www.scienex.com.br
calori@gmail.com
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