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.

problem in pic16f877a

Status
Not open for further replies.

jis

Junior Member level 3
Joined
Dec 17, 2011
Messages
27
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,501
hi all.........

i am doing a project using pic16f877a. And its my first experience with pic .i coded it using mikroc with default set up and i am using a 4mhz crystal and selected HS mode while flashing...at first i wrote a simple code to control 1 of the ic which is a part of my project.. it worked satisfactorly when i simulated using "PIC SIMULATOR"... but i am not getting any o/p when i flashed the same to pic ... Anyone pls help me out in solving this problem.. the code i wrote is as follows...


//This prog is to playback msg stored in ic apr9600. The msg stored in the field which is selected by making the msg select pin low. There are 8 msg fields and msg select bits are connected to portb

Code:
void main()
{option_reg = 0x80; //disable portb internal pullup
trisb = 0x00;
portb = 0xff;
while(1)
{
delay_ms(5000);
portb = 0x7f; //select 8th msg
Delay_ms(5000);
portb = 0xff;
delay_ms(5000);
portb = 0xbf; //select 7th msg
Delay_ms(5000);
portb = 0xff;
delay_ms(5000);
portb = 0xfb; //select3rd msg
Delay_ms(5000);
portb = 0xff;
delay_ms(5000);
portb = 0xf7; // select 4th msg
Delay_ms(5000);
portb = 0xff;
delay_ms(5000);
portb = 0xdf; //select 6th msg
Delay_ms(5000);
portb = 0xff;
delay_ms(5000);}
}


Thanks.........
 
Last edited by a moderator:

You are using 4Mhz Crystal and you have set ur configuration bit as HS

HS is used when u are using Crystal of >4Mhz Up to 4MHz Use XT

And remove this line OPTION_REG = 0x80 and then see whether ur code works or not..
 

Let me try it out....

Thanks
 

First establish if the PIC is running properly with this checklist:

1. Do you have both VSS and both VDD pins connected?
2. Do you have a decoupling capacitor across VSS and VDD lines and is it mounted as close as possible to the PIC?
3. What crystal frequency are you using and do you have the oscillator configured in the correct mode?
4. What are the values of the capacitors at each end of the crystal?
5. Do you have the reset line pulled high through a resistor to VDD?

Usually the problem you describe isn't in the software, it's either the PIC configuration or an electrical problem.

Brian.
 
  • Like
Reactions: jis

    jis

    Points: 2
    Helpful Answer Positive Rating
Thanks alot... I used a 4mhz xtal and configured it in HS mode,,,pic worked when i changed it to XT mode..
And why you asked about decoupling capacitor.. I havent connected it.. Still it worked.. So can you pls say why its recommended in ckt??????

Regards
Jis
 

Hey thanks alot.......It worked when I changed it to XT mode...
 

The capacitor is needed to act as a local reservoir of power to the PIC. Although it may seem adequate to simply connect supply wires, you have to consider that each wire has resistance and inductance, both increasing the impedance of the supply. When the PIC operates, many thousand internal gates and transistors switch on and off and as they do so, they each need a tiny but significant amount of current. Collectively, the amount of current starts to become important and is what you measure as the current drawn into the VDD supply lines. Because there are so many circuits switching at different times, the current waveform is very complex, in fact it looks like high frequency random noise. Without the decoupling capacitor the impedance of the supply wires allows the VDD line to convert the current into a voltage variation which in turn upsets the internal PIC circuits. When the capacitor is fitted, it provides a source of current right up to the PIC itself so the supply wiring becomes far less critical.

Your circuit might work without the capacitor but you may find it unreliable and more prone to interference or voltage variations than it should be. Good practice is to use two decoupling capacitors, one of a few uF to help with the slower current variations and one of around 100nF to help at higher frequencies. In general, larger capacitors, particularly electrolytic types, lose effectiveness as the frequency increases while lower value ceramic types work the other way around. If you connect both in parallel across VDD and VDD you get the best of both properties.

Brian.
 

Very Good

Always Refer Datasheet before Programming any Device..
And in MickroC During Initial Stages..
When u set 4MHz Crystal Frequency

It sets it configuration bit to XT By default
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top