Jump to content
Sign in to follow this  

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.




#include <system.h>




//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;






void main(void) {




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.

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.

Sign in to follow this  

  • Create New...