![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
DaveMorris
Joined: 13 Oct 2003 Posts: 6 Location: Stourbridge, England
|
PCM compiler / strcpy problem 3.245 and 3.249 |
Posted: Thu Apr 06, 2006 1:32 pm |
|
|
Is it me or is there a problem with how the compiler implements the strcpy() statement. Using compiler version 3.242 the follow code is ok - 3.245 and 3.249 don't work!
.................... {
.................... // Convert Msg to general format! is done by direct copy
.................... strcpy(&commsMsg.data[1], &rfRxBuffer.msg[3]);
1105: MOVLW 5D
1106: BSF 03.6
1107: MOVWF 38
1108: MOVLW 33
1109: BSF 03.5
110A: BCF 03.6
110B: MOVWF 26
110C: BCF 03.5
110D: BSF 03.6
110E: MOVF 38,W
110F: MOVWF 04
1110: MOVF 00,W
1111: BSF 03.5
1112: BCF 03.6
1113: MOVWF 28
1114: MOVF 26,W
1115: MOVWF 04
1116: MOVF 28,W
1117: MOVWF 00
1118: MOVF 00,F
1119: BTFSC 03.2
111A: GOTO 11E
111B: INCF 26,F
111C: INCF 27,F <---- Is this the problem?
111D: GOTO 10C
.................... ok = 1;
111E: MOVLW 01
111F: MOVWF 22
Tracing the code on the Emulator suggests that the pointers are not correct.
Comments Please |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 06, 2006 1:56 pm |
|
|
You didn't provide a test program or say what PIC you're using,
so I made one for the 16F877. I compiled it with PCM vs. 3.249
and it works OK. It displays the following in the terminal window:
That's the correct output.
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
struct
{
char data[10];
}commsMsg;
struct
{
char msg[10];
}rfRxBuffer;
//============================
void main()
{
rfRxBuffer.msg[0] = '0';
rfRxBuffer.msg[1] = '1';
rfRxBuffer.msg[2] = '2';
rfRxBuffer.msg[3] = '3';
rfRxBuffer.msg[4] = '4';
rfRxBuffer.msg[5] = '5';
rfRxBuffer.msg[6] = '6';
rfRxBuffer.msg[7] = '7';
rfRxBuffer.msg[8] = '8';
rfRxBuffer.msg[9] = 0;
strcpy(&commsMsg.data[1], &rfRxBuffer.msg[3]);
printf("%s\n\r", &commsMsg.data[1]);
while(1);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Thu Apr 06, 2006 2:03 pm |
|
|
If you have more than a single variable in a struct the compiler may be allocating them incorrectly (i.e. overlapping !!) it did in 3.242 and I have seen a post recently that mentioned a later version aswell.
Have a look at your symbolic file (.SYM) and see what addresses commsMsg and rfRxBuffer have been allocated.
PCM, I suspect you don't see it as the struct is the size of the char array.
See my original post:
http://www.ccsinfo.com/forum/viewtopic.php?t=26107&highlight=242
...its shows what I mean. Try 3.236. _________________ Regards,
Simon. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|