PDA

View Full Version : First time with external oscillator - 16F877a Not working



financecatalyst
- 14th October 2009, 20:01
Hello everyone
It was easy for me upto now using PICKIT2 and 16F690 for all my experiments.

This is the first time I am using an PIC with an external oscillator. My PIC is 16F877A. I have placed the 4Mhz ceramic two pin oscillator as said in the datasheet (between os1 and os2) and 15pF from osc pins to gnd. My program is simple and all pins need to be Digital I\O.
I am creating an .Hex file using PBP with MPLAB and then loading it onto my PIC using MELAB U2 USB programmer (Hope I can do it this way?)
Oscillator selection is XT, wdt on, PUT on, BOD on, Low V. Prog Disabled, Data EE.... On, Flash program Write Off, Code protect On AND my simple code is :
DEFINE OSC 4
intcon=0
adcon0=%000
adcon1=%1110
cmcon=%000
@ ERRORLEVEL -306 ( It is for my actual code which is very loooooooooooong)
trisb=%00111111
portb=0

Include "modedefs.bas"

while 1
toggle portb.6
pause 30
wend

The above is not working. Please help.

financecatalyst
- 14th October 2009, 23:26
Ok, now I even tried it with just the following code

while 1
toggle portb.6
pause 30
wend

Tried capacitor value from 15 pF to 39 Pf, but no response. By the way I am making the circuit in a breadboard & not a PCB:confused:

bogdan
- 15th October 2009, 00:12
osc1=input
osc2=output

mackrackit
- 15th October 2009, 02:53
Using MPLAB, GOOD!

First:
Turn off the setting of the fuses in your programmer software and do it in code or the *.inc file.

Second:
To make this all digital use


ADCON1=7
CMCON=7


Third:
Try this code before you write something "looooong", just to make sure everything is working.


'************************************************* ***************
'16F877A HEART_BEAT
DEFINE OSC 4
'####################
@ __config _XT_OSC & _WDT_OFF & _LVP_OFF & _CP_OFF &_BODEN_OFF
ADCON1=7
CMCON=7

START:
HIGH PORTD.2
PAUSE 100
LOW PORTD.2
PAUSE 100
GOTO START

financecatalyst
- 15th October 2009, 11:09
osc1=input
osc2=output

How do you figure that out with the ceramic oscillator? I only see two pins comming out and no specific I\O marking.

financecatalyst
- 15th October 2009, 11:57
Using MPLAB, GOOD!

First:
Turn off the setting of the fuses in your programmer software and do it in code or the *.inc file.

Second:
To make this all digital use


ADCON1=7
CMCON=7


Third:
Try this code before you write something "looooong", just to make sure everything is working.


'************************************************* ***************
'16F877A HEART_BEAT
DEFINE OSC 4
'####################
@ __config _XT_OSC & _WDT_OFF & _LVP_OFF & _CP_OFF &_BODEN_OFF
ADCON1=7
CMCON=7

START:
HIGH PORTD.2
PAUSE 100
LOW PORTD.2
PAUSE 100
GOTO START


Hi, thanks for replying. My Loooong code is working fine (Code is good) on 16F690. I want to transffer the code to 16F877 but since it uses external oscillator and I have never used one before, I only have intentions to blink an LED first.
I have tried your advise above but its not working still. Timing of blinking is not right (when it is blinking), it blinks sometimes when I touch the capacitor leg, touch the bench where the circuit is left on, sometimes its just sitting bright on. I feel the problem is with hardware configuration.
I am building the circuit on a breadboard with 4MHz ceramic oscillator and two 22pF ceramic capacitors. But just don't know what is wrong and it is taking me towards insanity....

mackrackit
- 15th October 2009, 12:09
Tell about the MCLR pin connection.
Is it pulled high?

Acetronics2
- 15th October 2009, 12:15
10 Bucks on Mackrackit ...

Alain

financecatalyst
- 15th October 2009, 17:14
Did I mentioned that some people here really know there stuff?
Thank you very much, this problem was due to MCLR!

But

I'LL BE BACK (with more problems ofcourse)

;)