Also,
How did you connect your LED to PORTB.0 ?
Usually, people make simple mistakes about it, and connect it WRONG.
___________________________________
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Well I connected it the positive side to PortB and connected the other side to ground.
If I didn't use a resistor would that stop the circuit from working just wondering?
First, if you don't use a dropping (current limiting) resistor between the PORTB.0 pin and the LED, it could cause damage to either the PIC or the LED when it does come on. If you're not getting any light from the LED, try turning it around. They are polarity sensitive since they are a diode. A good value for the resistor is 470 ohms. You can buy them at radio shack or a parts warehouse like Jameco. I would place a capacitor at the power supply pins of the PIC as the long leads of the regulated power supply can introduce noise and cause problems. Any 1 uf to 100uf, 16 volt capacitor will do. Also be sure to make sure it is connected properly as they get hot and blow up if connected backwards. Ther is a minus stripe on one side.
Also, LED's are polarity sensitive, meaning they only work hooked up one way. A round LED usually has a flat side or shorter lead that is the negative lead. Connect this to the same place as VSS and connect the black lead from the regulated supply to both. VDD is positive 5 volts.
Also connect a 470 ohm resistor to the MCLR pin. This will make sure the chip always runs.
If you have more than one LED handy, it might be helpful to simply attach one to the same place that supplys power to your pic (be sure to also include a resistor on this LED as well or else you'll fry the LED). If you put an LED on PORTB bit 0 without a resistor, it will cause the transistors that make up the logic in the PIC overheat and will damage part or all of the PIC. The current output of most of the pins on a typical PIC should not exceed 20MA, which is what the LED draws with a proper resistor. With out the resistor, a typical 2.1V LED will draw over 500MA and zap... you may only see a brief blink and its all over. It's all about ohms law... You can also control other things like 5 or 12 volt relays, but not directly from the pins of a PIC. You should use a transistor to power the relay, then the relay can turn on or off things like motors.
there are several ways to write the code that turns on and off the LED, including this one:
trisb = 0
START:
portb.0 = 0 'turn led off
pause 1000
portb.0 = 1 'turn led on
goto START
Sometimes, if I can't get a new design on my breadboard to work, a simple program like this is the best thing to start with, just to make sure my crystal, capacitors on it (22pf) and power supply are all working as expected. Then I build on design from there. There are plenty of snafu's that make it hard to get a PIC to do what you want, so keep in mind that ports that also share functions could default to work as (say for example, an Analog port), so they won't put out any voltsge. Then you have to figure out what combinations of commands put the port into the mode you expect - this can be a little frustrating, but don't give up easily. This is an excellent support group and they can help you get started. I've built some amazing stuff with these chips.
Also, invest in a good volt meter. Harbor Freight Tools sells a good basic digital volt meter for $2.99. You need to check the voltage at the pins of the IC and check the voltage on Portb.0. If you suspect that pin to not work, also try other pins on that port. (be sure to change the code to turn on or off the new pin)
portb.1 = 0 'turn off port b pin 1
portb.1 = 1 'turn on port b pin 1
Hope this helps,
Jason
Thank you that was very helpful
I know about basic electronics likes diode and capacitors and how current only flows one way in order for it to work.
I have a multi meter
I have built circuits but I usually follow off of a schematic and no programing necessary.
So when it comes to pics I am a big noob
but you guys have helped me a lot
So I am going to try everything out
I think I will use my PIC16F627A since I already probably messed up the chip but I will run my multi meter and see if I am getting anything out from port0 on the 16F84A if not I will just use the 16F627A with all the corrections.
Well thanks a lot I am going to try this stuff out and post my findings after I get some more parts, I am running low and out of stock on some components.
Well thanks everyone for your help
![]()
Bookmarks