Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

need help with my first PIC program

Status
Not open for further replies.
Try this...

DEFINE OSC 20

Trisb=%11111110 ' Portb.0 is Output Pin

Main:
Portb.0=1
Pause 3000
Portb.0 =0
Pause 3000
Goto Main
 

in a state of panic i rushed off to me sk00l where there is an oscilliscope.

in answer to your question(s).

yes i have tested the LED it is hooked up properly.

yes there is a 4.7K resistor for a pull-up on the MCLR (pin 1).

i am just now hooking up the oscilliscope, will inform on me results in a sec

Mr.Cool
 

sorry for the 3 same replies !! ...
i have receive 3 time .... error sending Mail :wink:

Darth ...
 

there are no oscillations! i think i may have found the problem.

I am using a 20MHz crystal, according to the PIC 16F877 datasheet the crystal requires 2 capacitors connected one to each leg and to ground. the value of the capacitance is a range of 15pF to 30pF (if memory serves me). the higher the capacitance the slower the startup time, but the more stable the oscillator.

with this in mind, i selected 27pF for each capacitor.

perhaps the breadboard i am using has a high capacitance that, when added to the 27pF capacitor it produces a high enough result that it keeps the crystal from oscillating??

Mr.Cool
 

i guess i'll have to wait until tomorrow to buy some other capacitors and try.

just for fun i took the capacitors out completely and applied power to the circuit. the LED came ON and remains ON. when i hit RESET the LED goes out and turns back on when RESET is released.

all the other values of PORTB are -v except portB.0

Mr.Cool
 

Really, if you have proteus, I would definitly simulate first in Isis. It is very easy. You just need to load up the processor from the library and place it on your drawing sheet. Load up a logic probe and connect to port pin 0. That is all you need to do, no osc or power conns reqd. When you have done this, right click on the processor, and then left click. A sheet should appear where you can set up the osc freq etc, and set up the location of the hex file that you wish to use.

Press the play button, bottom right. All being well, the logic indicator should flash on/off. If this works then you have a hardware problem, if not, then check your code.

BTW, what country are you in?.
 

i have simulated the code with proteus as suggested. it works fine, LED flahsing every 3 seconds.

i won't be able to experiment further until monday because all the stores are closed on sunday. i'll try a new breadboard first, and then different values of capacitors.

Mr.Cool
 

oh, i'm from CANADA.. eh?

Mr.Cool
 

Hmmm, 16F877. I seem to remember that this is a One Time Programmable (OTP) chip with EEprom. That is why you are getting check sum errors. I may be wrong, but check all the same.

You would be better of with something like a 16F84, then you can keep re-programming it.

If you had been in the UK, I could have sent you some bits to play with, thats why I asked.

Good luck, keep playing around and asking questions, that is how you learn.
 

16F877 is definately a flash part
 

i was told today that you can not measure the crystal frequency using an oscilliscope attached to the Clock In pin.. so maybe that's why i do not read any oscillations..

i rebuild the circuit onto perf-board. same result, no blinking light!

i must work harder to determine my fault

Mr.Cool
 

i have also tested my circuit on the old breadboard and the new perf-board version with a regulated power supply.

no blinking LED :(

Mr.Cool
 

Check what is happening with unused inputs.
You should set internal weak pullups on Port B if you have unused lines set as inputs. Otherwise they will oscillate and screw up the micro.
Cmos unused inputs must be tied somewhere! Outputs can go nowhere.
In future, unless you need the speed, a 3 terminal resonator will do for a clock, no caps needed.
Also, use mplab, a free download, and Pic asm, only 35 odd instructions, easy to learn and you have complete control.
Basic is just that, Basic!
Have a nice day.
:D
 

led flash

say MR cool
From what I have read, it sounds like you are having a circuit problem (hardware) and not a programing problem (firmware).
Do you reside in Edmonton by any chance; If so I may be able to help.
Please note: You can use a scope to measure/check for a clock on one of the pic osc pins, I cant remember which one but it is safe to check both.(I have checked the osc pins many times with my own scope no problem).
I m almost certain that the pic oscillator isn't working (as you mentioned that you could not see the clock frequency (scoped)). Make sure that you have used 27 to 33pf (Picofarad) caps with your crystal or the oscillator won't startup. Also make sure you have connected both the +positive Pic supply pins to the +5volt supply and both the Pic-neg pins to the -neg supply. Yep thats right the Pic f877 has 4 power pins to worry about and if you miss one of the power pin connections, the Picf877 wont work properly or, it wont work at all.
Have you tried using another crystal, say a 4mhz jobby for instance? Even though your Pic IC maybe a 20Mhz capable jobby, a 4mhz crystal will work just fine but will achieve 1/5 the execution speed (your led will flash one fifth as fast but the pic IC will execute more reliably). This is useful when trouble shooting hardware or debugging program code.
Also have a look at the complete part number on your Pic IC and let me know what it is. If you see an A or an OT in the part number, then that IC is a special case IC. OT means that the IC is a one time only programmable device. Even though The (OT) part is half the price (about $5cdn) you definetley DON"T want that one.
The meaning of the letter (A) is long and not too important at this stage.

End
 

fuses

hi,

in the prog u listed above, i dont see any
'reset-watchdog-timer' instruction
result is, that the pic will keep resetting itself in a loop
after the watchdog is reached his time , after xxx ms

therefore,

when programming in picallw, disable watchdog timer !

that is a mistake very often made !

greetz, gelly
 

Mr Cool ,

Forget about the software its sounds like a hardware issue. I had exactley the same problem when I first started using PICs ! The Crystal needs 2 capacitors tied to ground to work correctly. I normally use 30pF but 27pF will do .

The problem I had was due to me using strip board (or vero board)! This stuff has terrible stray capacitance ! You need to solder the crystal as close to the PIC as you can and cut any additional track thats left over. Make sure you also clean off the flux residue when you solder the joints as Ive seen that pulling the crystal down as well !.

The 16F877 is 100% definatley a flash part and not a OTP part > Thats what the "F" stands for.

I have tried to measure crystals using an oscilloscope in the past and the capacitance of the probe normally pulls the crystals down ! Unless you have very good and typically very expensive probes.

Hope this helps

Schmitt :lol: :lol:
 

still not working... i'm really getting worried.

i have now a breadboard with a 4MHz. i did not know that i had to power all 4 power ports. i powered the pins to proper supply and ground. this did not make a difference, still no flashing. the LED does flash when i test it seperately, so its not burnt out or anything.

The PIC chip i am using is: PIC16F877-04I/P

Someone told me that this device is max 4MHz. so i built up a breadboard, with 2 power and ground lines as per datasheet pinout. i used a 4MHz crystal. tested it. nothing.

my caps were bought from surplus store from the 27pF labeled container. they are numbered 27KS2L.

i apply the scope to any leg of the crystal and do not see oscillation. this was verified by someone else too.

i am really at a loss and am getting worried.
are there any other thing i can try??

i am from Ontario, not edmonton :(

Mr.Cool
 

also, i programmed the pic with picall and set the config file such that everything was OFF, i.e. no check marks. XT selected.

Mr.Cool
 

Mr Cool,

Your chip is a definatly a 4MHz version , the -04 at the end tells you that . If you had a 20MHz version it would be -20 etc.

What type of breadboard are you using ?

Is it the solder type (eg vero board or strip board ) or is it the plastic breadboard type where you plug components into without soldering ?

Schmitt :lol:
 

To get the clock running try putting a 22-meg resistor across the XLT.
This helps the clock get started at DC.

Also add a 100 ohm resistor to the OSC2/CLKOUT pin (14). Some XTLs are don't like the high signal levels that come out of the PIC. The resistor should be between the PIC and the XTK.

Make sure that the reset (-MCLR) pin is hi.

Note: with a 10x probe you should be able to see clock signal on the PIC clock pins (13&14)

Good Luck
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top