Jump to content
Sign in to follow this  
Mitch

Xtal Osc On 16f777 - Help Please

Recommended Posts

I can't seem to get the 4MHz external XTAL osc working on my 16F777.

I program the following code onto the chip (along with the config/fuses)

And the program works, but it also works when I remove the XTAL.

This makes me think it's only using the INTRC osc.

Can anyone find anything wrong with the code or offer me any advice?

Is the "osccon" line what is throwing it off?

 

Thanks for your help.

 

 

//16F777

#include <system.h>

//#pragma DATA _CONFIG, _PWRTE_ON & _WDT_OFF & _INTRC_IO & _CP_OFF & _MCLR_OFF & _IESO_OFF

#pragma DATA _CONFIG, _PWRTE_ON & _WDT_OFF & _XT_OSC & _CP_OFF & _MCLR_OFF & _IESO_OFF

 

//Set clock frequency

#pragma CLOCK_FREQ 4000000

 

void Startup(void) {

 

osccon = 0b01101110; //Set oscillator to 4MHz

adcon1 = 1111b; //Set all pins to digital

 

trisa = 0b00000000; //Set porta for output

trisb = 0b00000000; //Set portb for output

porta = 0;

portb = 0;

 

delay_s(1);

 

}

 

void main(void) {

 

Startup();

 

while(1) {

porta = 1; delay_s(1);

porta = 0; delay_s(1);

}

 

}

Share this post


Link to post
Share on other sites

Bits 1-0 in osccon are indeed telling the chip run from its internal oscillator.

To tell it to use the oscillator as defined in fuses FOSC setting bits 1-0 of osccon should both be set to 0.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...