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

Strange compilation problem

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



Joined: 18 Feb 2011
Posts: 7

View user's profile Send private message

Strange compilation problem
PostPosted: Fri Feb 18, 2011 1:32 pm     Reply with quote

Hello!

I'm working on a very simple project with a 12F629 but I'm stuck in a problem I can't understand...

C Code:

Code:
#include "C:\ServoDecoder_PIC\servodecoder.h"
void main() {
   while(1) {
      output_bit(PIN_A0, !input(PIN_A0));
      delay_ms(500);
   }
}


H Code:

Code:
#include <12F629.h>
#use delay(clock=4000000)

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOCPD                    //No EE protection
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BANDGAP_HIGH


When I compile, here's the ASM:

Code:
0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   004
0003:  NOP
0004:  CALL   3FF


As you can see, it calls the last (3FF) address of program memory and stops... do you see any mistakes in my H file?

If I remove #FUSES declarations, the assembly is ok:

Code:
0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   018
0003:  NOP

.................... void main() {
0018:  CLRF   04


Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 18, 2011 1:41 pm     Reply with quote

What's your compiler version ?
lukyluke



Joined: 18 Feb 2011
Posts: 7

View user's profile Send private message

PostPosted: Fri Feb 18, 2011 1:44 pm     Reply with quote

Hello

4.057, with a further investigation it seems INTRC_IO is the problem, if I change to XT (for example) the ASM generated is correct...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 18, 2011 1:57 pm     Reply with quote

It works for me. I installed vs. 4.057, and took your code and pasted it
into an MPLAB project as one program (no separate servodecoder.h file).
The .LST file doesn't stop at 0004.
Code:

CCS PCM C Compiler, Version 4.057, xxxxx       18-Feb-11 11:55

               Filename: 12F629_Test.lst

               ROM used: 55 words (5%)
                         Largest free fragment is 969
               RAM used: 6 (9%) at main() level
                         7 (11%) worst case
               Stack:    1 locations

*
0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   004
0003:  NOP
0004:  CALL   3FF
0005:  BSF    03.5
0006:  MOVWF  10
0007:  MOVLW  00
0008:  MOVWF  0A
0009:  GOTO   01E

Code:

#include <12F629.h>
#use delay(clock=4000000)

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOCPD                    //No EE protection
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BANDGAP_HIGH

void main() {
   while(1) {
      output_bit(PIN_A0, !input(PIN_A0));
      delay_ms(500);
   }
}
lukyluke



Joined: 18 Feb 2011
Posts: 7

View user's profile Send private message

PostPosted: Fri Feb 18, 2011 2:03 pm     Reply with quote

thanks for your support... very strange I've just copy&paste your source code in my C file, and here's the result:

Code:
CCS PCM C Compiler, Version 4.057, xxxxx               18-feb-11 21.01

               Filename: C:\ServoDecoder_PIC\servodecoder.lst

               ROM used: 55 words (5%)
                         Largest free fragment is 969
               RAM used: 6 (9%) at main() level
                         7 (11%) worst case
               Stack:    1 locations

*
0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   004
0003:  NOP
0004:  CALL   3FF
0
lukyluke



Joined: 18 Feb 2011
Posts: 7

View user's profile Send private message

PostPosted: Fri Feb 18, 2011 2:11 pm     Reply with quote

mmm maybe I wasn't clear in my explanation: my ASM source doesn't stop at 0004, but the instruction at that address make a CALL to the last memory address (CALL 3FF) and the program stops (with a simulator or with a "real" circuit the led doesn't blink)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 18, 2011 3:35 pm     Reply with quote

OK, now I understand. Your problem is not with the .LST file. It's with
program execution. See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=27234
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Fri Feb 18, 2011 3:44 pm     Reply with quote

And to explain 'why'. The chip's come from the factory, with a single instruction at address 0x3FF, 'preprogrammed' by the manufacturer. The instruction is a RETLW, returning a value designed to calibrate the internal oscillator. This is called the 'OSCCAL' (oscillator calibration) value.
Yours has had this value erased.

The thread PCM programmer points you to, shows how to put a 'mid range' value back into this location, but understand that the calibration will have been lost, so frequencies won't be that good.
For 'future reference', look into your programmer settings. there should be an option to 'save OSCCAL', or 'preserve calibration', and you need to select this, otherwise you will do the same to the next chip you try....

Best Wishes
lukyluke



Joined: 18 Feb 2011
Posts: 7

View user's profile Send private message

PostPosted: Sat Feb 19, 2011 4:55 am     Reply with quote

Friends,

Thanks for your suggestion and the explanation (very interesting, I never investigated about the OSCCAL feature): it worked fine and I was able to find - in my software - the flag to preserve the value at 0x3FF address when programming my HEX.
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