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

Cannot get PIC16F747 to run with internal oscillator

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



Joined: 15 Mar 2005
Posts: 2

View user's profile Send private message

Cannot get PIC16F747 to run with internal oscillator
PostPosted: Tue Mar 15, 2005 10:57 pm     Reply with quote

I have been able to run my PIC16F747 with an external 20MHZ crystal. Now when I change the oscillator setting from HS to INTRC or INTRC_IO in the #fuse command line, the PIC will not run. I even set OSCCON to 0x74 without any luck.

With the same OSCCON setting, I was able to run the PIC with the CC5X compiler and the internal oscillator without any problems. It looks like there is some bug in the compiler.

The compiler version is 3.181 if that helps.

Here is my code:

test.c:
#include "test.h"

#use delay(clock = 8000000)

void main()
{

OSCCON = 0x74;

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);

set_tris_A(0);

while(1)
{
OUTPUT_A(0xFF);
delay_ms(200);
OUTPUT_A(0x00);
delay_ms(200);
}

}


test.h:
#include <16F747.h>
#device *=16
#device adc=8
#use delay(clock=20000000)
#fuses NOWDT,INTRC_IO, NOPUT, NOPROTECT, BROWNOUT, BORV20, NOMCLR, NODEBUG
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)
#BYTE OSCCON = 0x8F
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 16, 2005 12:46 am     Reply with quote

The first thing I would do is make a test program that's not split up
into two files. See below.

The main problem is that your version of the compiler is buggy for
the 16F747.

1. In the code that occurs right after the reset vector (at 0x0000), it's
calling location 0xFFF. Then it puts W into OSCCON.
This is wrong. I think when CCS saw an OSCCON register,
they thought it was an OSCCAL register as in the 12F675, and
treated it in the same way. Here's part of the .LST file.
The code appears to call 7FF, but it's actually FFF because of
the value loaded into PCLATH right before that.
Code:

0000:  MOVLW  00
0001:  MOVWF  0A
0002:  GOTO   004
0003:  NOP
0004:  MOVLW  0F
0005:  MOVWF  0A
0006:  CALL   7FF
0007:  BSF    03.5
0008:  MOVWF  0F
0009:  MOVLW  00
000A:  MOVWF  0A
000B:  GOTO   020

I don't think you can change the CCS code in that area.
So as a work-around, you can just place a RETLW instruction
at 0xFFF and have it return your desired value for the OSCCON
register. Do this with a #ROM statement. See the line shown
in bold, below.

The CCS start-up code for the program below, loads 0x70 into
the OSCCON register. This occurs several instructions after
it has called location 0xFFF. So it's basically doing what you
want, anyway. You just have to fix it so it doesn't crash when
it calls 0xFFF, and that can be done with the #ROM statement.

I noticed that you want to load OSCCON with 0x74. According to the
data sheet, bit 2 of that register (IOFS) is read-only. So OSCCON
should probably should be set to 0x70 to select the 8 MHz internal
oscillator, and not 0x74.

2. There's a problem with the setup_adc() function. It doesn't
generate any code. Look at the .LST file to see this.
As a work-around, you can define the ADCON0 register with
a #byte statement and write 0x00 directly to it.

Now, as what you should do about all this... You can try these
work-arounds, or maybe you can report these bugs to CCS and
get them to give you an upgrade. I'm not sure what their policy
on this is, but sometimes people report that if their version is
very buggy, then CCS will upgrade it.

I looked at the code produced by vs. 3.219, which is fairly recent,
and all these problems appear to be fixed.


#include <16F747.h>
#device *=16
#device adc=8
#fuses INTRC_IO, NOWDT, NOPROTECT, PUT, BROWNOUT, BORV20, NOMCLR, NODEBUG
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#BYTE OSCCON = 0x8F
#byte ADCON0 = 0x1F // Add this line.

// Add the following line.
#ROM 0xFFF = {0x3470} // Return 0x70 in the W register

void main()
{

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
ADCON0 = 0x00; // Add this line
set_tris_A(0);

while(1)
{
output_a(0xFF);
delay_ms(200);
output_a(0x00);
delay_ms(200);
}

}
fsimjee



Joined: 15 Mar 2005
Posts: 2

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 12:43 pm     Reply with quote

Thanks a lot! Worked like a charm!
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