# PIC16F877A based project

#### harami

Joined Jun 20, 2011
66
Im new to the PIC world and am having difficulties using it in my project. My project is a simple lighting control system. I already written the program (code). I programmed the PIC and build it on a breadboard. I also build a external RC ocillator. But I still get zero output.

PIN 19,20,21 - output from the pic to the keypad
PIN 27,28,29,30 - input to the pic from the keypad
PIN 23,24,25,26 - output from the pic, connected to the leds

PIN 1 - 5V pow
er supply
PIN 40 - GND

PIN 13, 14 - RC ocillator

Also, on pic16f877a, PIN 11,12 and 31,32 they both are VSS and VDD. So can we use only one of them or do we have to use both of them.

Can you guys help me PLEASE!!!

Last edited:

#### t06afre

Joined May 11, 2009
5,934
Can you guys help me PLEASE!!!
Not before you post code and schematic

#### debjit625

Joined Apr 17, 2010
790
And also post your configuration settings, if you are configuring them from your programmer application.

#### John P

Joined Oct 14, 2008
1,782
Possible problems (with no diagram, can't say for sure):

Oscillator isn't right/doesn't match config word

You've used low-voltage programming and haven't grounded Portb.3

Reset pin not correctly wired

You didn't use Port B for the inputs from the keypad, and didn't install pullup resistors

#### ErnieM

Joined Apr 24, 2011
8,010
Possible problems (with no diagram, can't say for sure):

Oscillator isn't right/doesn't match config word

You've used low-voltage programming and haven't grounded Portb.3

Reset pin not correctly wired

You didn't use Port B for the inputs from the keypad, and didn't install pullup resistors
QFT.

Also, check the pins used as digital are not being default configured to analog functions. Especially check pins with an "AN#" option.

#### harami

Joined Jun 20, 2011
66
thank you everyone for your replies... i have attached my circuit design and the code.
Thank you for your help..

#### Attachments

• 2.4 KB Views: 56
• 81 KB Views: 118

#### debjit625

Joined Apr 17, 2010
790
I didn’t gone through your code, but then also as per your schematic their are a lots of problem,
1) First the current limiting resistor for the LEDs are 1K which will limit the current too much you should use 330 ohms instead.
2) Your configuration setting for oscillator is RC but you wired a crystal for that your setting should be HS(High Speed Crystal/Resonator).And that 10K resistor to pin 14 is not needed unless it’s a AT strip cut crystals or if it's the case of overdriving.
3)And pin no 12 and 31 should be connected to Vss i.e.. GND
4)Normally we use 0.1uF rather 1nF.

Good luck

Last edited:

#### ErnieM

Joined Apr 24, 2011
8,010
To expand on debjit's... that's 1nf to 0.1 as a bypass cap. For the crystal I've normally seen values such as 22pF there but that depends on the exact crystal you used (meaning it's probably on the data sheet for the crystal). 1K on the LEDs may be OK, they ain't gonna be bright but I've done that before.

How are you programming this? Pins 39 & 40 are used for programming but you have 40 grounded. MCLR on pin 1 is good, without that resistor these things tend to only work when the programmer is connected. 1K may be low, 10K is typical.

Additionally, when posting a micro's schematic it is best to indicate what function you are using on the pins, otherwise we'd have to look up the part and write that in to see all of what you're doing. (And guess what? I ain't a gonna do that! )

#### stahta01

Joined Jun 9, 2011
133
This is stupid, I am not going to waste my time looking up what "5" means.

Rich (BB code):
BSF STATUS,5        ;BANK 1
Learn to use the inc file; do not define the things all over again.

Rich (BB code):
PLC    EQU 02h
PORTC    EQU 07h
PORTD    EQU 08h
TRISC     EQU 87h
TRISD     EQU 88h
KEY     EQU 20h
STATUS     EQU 03h
Learn to use the proper columns in assemble.
Your code had over a dozen column warnings.
instruction can not be in first columns.
labels must be in first columns.

Tim S.

#### ErnieM

Joined Apr 24, 2011
8,010
Tim?

Is there perhaps a gentler way to convey this information to harami? After all, he is new here and it does take some guts to present your work to strangers for review.

I know you have 3 whole posts more then harami and you do have several legitimate points here, just please try to be encouraging towards someone who is doing honest work while struggling with both hardware and software issues on his first project.

#### stahta01

Joined Jun 9, 2011
133
But I still get zero output.

PIN 19,20,21 - output from the pic to the keypad
PIN 27,28,29,30 - input to the pic from the keypad
PIN 23,24,25,26 - output from the pic, connected to the leds
I suggest measuring one or more of the outputs and verify it is changing from high to low.

If not, the first thing to check is Power and Ground hooked up right.
Second, is external crystal circuit correct.
debjit625 says there might be an issue there.

Note: I suggest using a know good simple program to confirm the hardware setup above is correct.

I suggest one that is only changing a single output pin to confirm the software and hardware works together.

Tim S.

#### t06afre

Joined May 11, 2009
5,934
A programmer is not a prgrammer, unless he/she is able to utelize the power of the availible tools. And herby be able to debug and simulate code. The hobbyist may not have accsess to fancy (and expensive) hardware debugging tools. But the fact is that many errors can be tracked down with the software simulator tool named MPLAB SIM.

#### stahta01

Joined Jun 9, 2011
133
Third thing to check is the right voltage the reset/ master clear pin.
It looks like you already have this on pin 1.

Tim S.

#### harami

Joined Jun 20, 2011
66
as far as the code is concern, i do get lots of warnings however i managed to minimise all the errors. i compiled it using MPLAP IDE and it worked perfectly. but when i put it on a breadboard i get nothing which proves that there is something wrong with the circuit.

as the PIC16F877A haven't got internal oscillator, i have config RC_OSC on the code and build a RC oscillator circut. i connected pin1 to 5 V power supply. i searched for pic16f877a based projects to understand how the circuit are built and what needs to be connected to the pic in order to make it work. but i cant find any relevant information. can anyone tell me if i need to add anything else to my circuit. and if possible can anyone give me a rough circuit diagram for this project. with this project im going nowhere and i really need help from you guys... PLEASE!!

#### stahta01

Joined Jun 9, 2011
133

Per Table 14-2 You need to use HS for a normal 6MHz Crystal and the Caps should be 15pF; and remove the 10K resistor unless you have a valid reason to have it. If you do, state that reason.

You need to use _HS_OSC instead of _RC_OSC.

Tim S.

#### harami

Joined Jun 20, 2011
66
as i have already used _RC_OSC, i will connect a RC oscillator circuit to the pic. it does not make any difference which ever OSC i config or dose it? im using 10k resistor and 1nf caps for RC oscillator circuit. do u think this will be appropriate?

Also i need a power supply for 3 different pins. do i need to supply 5V individually or shall i connect it all to a 5v power rail?

#### stahta01

Joined Jun 9, 2011
133
as i have already used _RC_OSC ...

You need to use _HS_OSC !!! Edit: This assumes you are still using the 6MHz Crystal.

im using 10k resistor and 1nf caps for RC oscillator circuit. do u think this will be appropriate?
No, I do NOT think it is correct; please read the datasheet.
Or, have you decided not to use a Crystal?

What type of Crystal are YOU using?

Tim S.

Last edited:

#### ErnieM

Joined Apr 24, 2011
8,010
as i have already used _RC_OSC, i will connect a RC oscillator circuit to the pic. it does not make any difference which ever OSC i config or dose it? im using 10k resistor and 1nf caps for RC oscillator circuit. do u think this will be appropriate?

Also i need a power supply for 3 different pins. do i need to supply 5V individually or shall i connect it all to a 5v power rail?
Per the fine manual Fig 14.3 use an R between 3K and 100K (so 10K is good) and a C of greater then 20 pF, so again 1 nF is also good.

Connect all the 5V stuff to the 5V rail. What else could you do, use multiple 5V supplies?

#### harami

Joined Jun 20, 2011
66
i have attached my circuit design. i build my circuit as shown in this design but it still not working. can anyone please help me. deadline for this project is in 2 weeks time and i still cant figure out the problem. can anyone please have a look at my circuit diagram...

#### kavli

Joined Aug 1, 2011
23
Before we can get any further, you need to tell if you're using an RC oscillator or an X-tal, as your diagram suggests.

An X-tal (Crystal) is not the same thing as an RC oscillator. An RC-oscillator is made from a resistor and a capacitor, hence the name. And because those two oscillator circuits are fundamentally different seen from the controller point of view, you need to specify the correct config word when programming the device, as several has suggested in this thread. Please review those comments.

-- K