Jump to content
Netlab

Pic16f819 Oscilator Issues?

Recommended Posts

Hi,

 

I am currently trying to get a PIC16f819 to flash two LEDs on and off, with the internal oscilator set at 8MHz. I'm using the code at the bottom of this post, the original code found at the link below - which uses an external oscilator set at 4MHz:

 

http://forum.sourceboost.com/index.php?sho...mp;hl=beginner),

 

However, it is not working properly, some random events are happening. One LED will come on, then if I touch any metal part of the circuit both LEDS start to flash correctly. I've made my own circuit board to eliminate the option of a dodgey bread board, and put a Cap across the power supply.

 

If someone could give some advice it would be greatly appreciated.

 

 

#include <system.h>

#pragma CLOCK_FREQ 8000000  // config clock to 8mhz.


#pragma DATA _CONFIG,  _INTRC_IO & _WDT_OFF & _CP_OFF & _PWRTE_OFF


void main() 
{
  osccon = 0x74; //setting oscilator to 8MHz
  trisb = 0;		//configure port B pins as output
 while( 1 )	  //endless loop
  {
 portb.0=1;		// set portb pin0 to high.
 portb.1=0;		// set portb pin1 to low.
 delay_ms(50);  // pause 0.5 seconds
 portb=0x02;	   // shows hex notation for entering data.
 delay_ms(50);	// you can also write portb=2 in decimal
  }
}

Share this post


Link to post
Share on other sites

Your CONFIG says you are using low voltage programming (default).

 

If this is what you want, have you taken all the precautions about RB3 pin not floating etc.

 

If you don't use LVP then add _LVP_OFF to your CONFIG.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites
Your CONFIG says you are using low voltage programming (default).

 

If this is what you want, have you taken all the precautions about RB3 pin not floating etc.

 

If you don't use LVP then add _LVP_OFF to your CONFIG.

 

Cheers

 

Reynard

 

 

WOW!! Not really sure why this works....but it is working beautifully. I just added the _LVP_OFF like you say and its all good. I'm using a programmer supplied by a 9V plug pack. Does this make sense to use _LVP_OFF?

 

Thanks a lot Reynard.

Share this post


Link to post
Share on other sites

A lot of programmers use a switcher or charge pumps to generate the 12-13 volts required for programming.

 

LVP is generally used for "on-board" programming when your only voltage source is the Vcc supply (Vdd).

 

Cheers

 

Reynard

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...

×
×
  • Create New...