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.

PIC16f877a code running problem

Status
Not open for further replies.

niranjan23

Member level 5
Joined
Jan 22, 2012
Messages
94
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
2,109
Hello!
Recently I bought new PIC programmer PICkit2 and PIC16F877A microcontroller IC. I just made one simple LED blinking Program using HiTech C compiler with Configuration bits and I program the 16f877a ic successfully with exported hex file.
Now my problem is I programed 16f877a perfectly but it is not working on development board of PIC16f877a.
Simply the program I made fro led blinking is not running on hardware but it run on Proteus simulator.
asd.png
This is the program for LED Blinking on PORTB.

Code:
#include<htc.h>
#define _XTAL_FREQ 20000000

void main()
{

TRISB=0x00;
  PORTB=0X00;
while(1)
{
PORTB=0x00;
_delay(1000);
PORTB=0xff;
_delay(1000);
}
}

The programming software which I used is PIC kit2v2.61


I'm confused and I dont knw what is Wrong I am doing?? Plz Plz help me with this, Im very grateful to You!
 
Last edited by a moderator:

Your CONFIG word suggests you have it set to LVP mode. Try turning LVP mode off and program it again.

Brian.
 

you have clock set to 20Mhz...that's a period of 50nanosecond
maybe delay(1000) means 50*1000 nanosecond which is just 50us...and maybe its too fast for you to see it blink
 
  • Like
Reactions: musta

    musta

    Points: 2
    Helpful Answer Positive Rating
@betwixt how can I turn off LVP mode in MPLAB V8.91?? there are only two option not off and on options!!!
@treez you may be right but its not only the single case ...when I toggal the all pins of portB like 0xAA; and 0x55;
hex the led still remainsON same like 1 off and 1 on...in alternative pattern..but they dont toggal literary.
what does it means??
 

can you make them turn off and stay off?...and...
can you make them turn on and stay on?

ie, are you actually 'talking' to that micro at all?

I don't know but I thought there was an updated thing on from MPLAB. Maybe uts best you use that then go to correct forum here or microchip forum
 

I think the _delay() parameter is in microseconds so I would expect 1 second on then one second off.

Niranjan23, I do not have a copy of HiTech C but I believe it is similar to Microchips XC8 compiler. If I'm right, look for a line starting "#pragma" with the setting "LVP=ON" in it then change it to "LVP=OFF". You then have to recompile the program so the new setting gets embedded in the hex file.

If Hitech has a configuration window of it's own, look in there instead and make sure it's turned off.

Also check you have a pull-up resistor between MCLR and VDD (~10K), it is needed in hardware but I think Proteus ignores it.

Brian.
 
can you make them turn off and stay off?...and...
can you make them turn on and stay on?

ie, are you actually 'talking' to that micro at all?

I don't know but I thought there was an updated thing on from MPLAB. Maybe uts best you use that then go to correct forum here or microchip forum

@treez None of above u said isnt working now!! but when I physically touch PORTB pins then LED on pin RB7 gets ON...and when I untouch it get OFF(In case of single bit operation)What is that..??Is that my hardware problem or software problem??

- - - Updated - - -

I think the _delay() parameter is in microseconds so I would expect 1 second on then one second off.

Niranjan23, I do not have a copy of HiTech C but I believe it is similar to Microchips XC8 compiler. If I'm right, look for a line starting "#pragma" with the setting "LVP=ON" in it then change it to "LVP=OFF". You then have to recompile the program so the new setting gets embedded in the hex file.

If Hitech has a configuration window of it's own, look in there instead and make sure it's turned off.

Also check you have a pull-up resistor between MCLR and VDD (~10K), it is needed in hardware but I think Proteus ignores it.

Brian.

I increased my delay in program and I connected 10k resistor to MCLR and VDD!! ALso Im searching "#pragram" but still not found solution!!

These are the Images of my board with Circuit diagram.
06032016523.jpgASDF.jpg
 
Last edited:

when I physically touch PORTB pins then LED on pin RB7 gets ON...and when I untouch it get OFF(In
sunds like you have noise pick up from unconnected input pins...if pin is unconnected, then make it an output
 
Ohk Thanks For helping me treez and betwixt....I will try from begining !!!
 

It still sounds like an LVP problem to me. When LVP is selected, PORTB bit 3 becomes a selector pin for programming (=1) or normal mode (=0). If it is left floating, or the internal PORTB pull-ups are turned on, the PIC will not run and you risk corrupting the program. To see if I'm right, connect a wire between PORTB.3 (pin 36) and VSS. If that makes it work, you can leave it like that or turn the LVP mode off. Note that you can't use PORTB.3 for anything else while you are in LVP mode, it becomes dedicated to selecting programming mode.

Your schematic is also missing two vital components. You should have two capacitors (suggest 100nF) wired directly between the VSS and VDD pins, one on each side of the PIC. They should have wires as short as possible.

I can't see the green electrolytic capacitor on the schematic. Where is it wired?

Brian.
 
Hi,

I think the _delay() parameter is in microseconds so I would expect 1 second on then one second off.
If delay() is in microseconds, then 1000 microseconds make 1 millisecond.

Pleas review the delay() function. Often I see the delay_ms function.

Klaus
 
It still sounds like an LVP problem to me. When LVP is selected, PORTB bit 3 becomes a selector pin for programming (=1) or normal mode (=0). If it is left floating, or the internal PORTB pull-ups are turned on, the PIC will not run and you risk corrupting the program. To see if I'm right, connect a wire between PORTB.3 (pin 36) and VSS. If that makes it work, you can leave it like that or turn the LVP mode off. Note that you can't use PORTB.3 for anything else while you are in LVP mode, it becomes dedicated to selecting programming mode.

Your schematic is also missing two vital components. You should have two capacitors (suggest 100nF) wired directly between the VSS and VDD pins, one on each side of the PIC. They should have wires as short as possible.

I can't see the green electrolytic capacitor on the schematic. Where is it wired?

Brian.

I didnt ..I jst connected to VSS and Vdd. ...Fortunately I found something in configuration bits of MPLAB v8.91 that is the RB3 is digital i/o pin HV on MCLR must be used for programming I selected this option in cong bits unless of LVP....ANd it works for me ....Now LED is turning on and off. Thankyou very much !!!
 

HV programming is the opposite of LVP (Low Voltage Programming) so you found the right thing with different words. Well done!

Still add those capacitors though or you will face problems later.

Brian.
 

HV programming is the opposite of LVP (Low Voltage Programming) so you found the right thing with different words. Well done!

Still add those capacitors though or you will face problems later.

Brian.

Ohk I will and I will keep that in mind Thanks Again!!!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top