View previous topic :: View next topic |
Author |
Message |
xcamarox
Joined: 18 Oct 2006 Posts: 9
|
Chip is not getting programmed... |
Posted: Tue Oct 31, 2006 4:04 pm |
|
|
I have the PIC16F877A and every time I program it with MPLab everythign programs fine, but when I try the chip it does not work.
For example...here is the code...
#include "XXXX\AC Zoned.h"
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
while (1 == 1)
{
if (PIN_B1 == 1)
{
output_high (PIN_D0);
output_low (PIN_D1);
output_low (PIN_D2);
output_low (PIN_D3);
}
else if (PIN_B1 == 0)
{
output_low (PIN_D0);
output_high (PIN_D1);
output_high (PIN_D2);
output_high (PIN_D3);
}
/////////////////////////////////////////////////////////////////
} //end while loop
} //end program
When I apply 5V to pin B1 nothing happens, all it happens is that most of the pins in the whole PIC read about 1.98-2.12V. Pins D1-D3 and most of the other pins read the same ~2V.
My header file lloks like this...
#include <16F877A.h>
#device adc=8
#use delay(clock=20000000)
#fuses NOWDT,HS, NOPUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT
Do you guys see anythig wrong with this?
One more point is that Im using the chip outside the Olimex package, if that matters. Im powering the chip with 5V and connecting the crystal, where it belongs and connecting MCLR to 5V through a 1K resistor.
Any help will be appreciated...
Sorry for the longggg post.
TIA! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 31, 2006 4:29 pm |
|
|
I wonder if the PIC's oscillator circuit is running. You connected a
crystal but you didn't mention the 22 pF capacitors that need to go on
each side of the crystal, to ground. Do you have those installed ?
What is the "Olimex package" ? If you're using an Olimex board,
then post the part number of the board so we can look at the schematic. |
|
|
xcamarox
Joined: 18 Oct 2006 Posts: 9
|
|
Posted: Tue Oct 31, 2006 6:53 pm |
|
|
PCM Programmer, thanks for the quick reply... yes I did install the 22pF capacitors between the oscillator legs and ground...It is the Olimex BOARD, not package (excuse my ignorance). I was wondering the same about the crystal. The funny thing is that it is connected right...
The Olimex is this one....http://www.olimex.com/dev/pic-p40.html... |
|
|
xcamarox
Joined: 18 Oct 2006 Posts: 9
|
|
Posted: Tue Oct 31, 2006 7:12 pm |
|
|
Actually I posted my connections in this ftp server if you want to take a look at them...
ftp://65.83.142.219
User: PCM
Pass:1234
Thanks. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Tue Oct 31, 2006 8:40 pm |
|
|
How do you know its not working?
Are you using a logic probe?
Are you using a cro?
If you are just using a multimeter you will not see anything useful.
Try this
Code: |
while (1 == 1)
{
if (PIN_B1 == 1)
{
output_high (PIN_D0);
output_low (PIN_D1);
output_low (PIN_D2);
output_low (PIN_D3);
}
else
{
output_low (PIN_D0);
output_high (PIN_D1);
output_high (PIN_D2);
output_high (PIN_D3);
}
delay_ms(1000);
}
|
_________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Guest
|
|
Posted: Wed Nov 01, 2006 9:02 am |
|
|
asmallri, thanks for the time to look into this.
I know its not working because the pins (D0, D1, D2, etc...) do not do what they are supposed to do (turn on or off through LED's). I will try the delay and report back. At this point anything helps because Im lost.
Thanks guys for your time once again.
I will report back. |
|
|
xcamarox
Joined: 18 Oct 2006 Posts: 9
|
|
Posted: Wed Nov 01, 2006 1:19 pm |
|
|
Still, no dice. The chip is not getting programmed. It is getting powered but when I put 5V on B1 and nothing happens to D1-D3...
Any insights?
TIA! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 01, 2006 1:42 pm |
|
|
That line of code is comparing two dissimilar constants.
The expression will always evaluate to FALSE.
The if statement will never execute.
You have to use the input() function to read a pin. |
|
|
xcamarox
Joined: 18 Oct 2006 Posts: 9
|
|
Posted: Wed Nov 01, 2006 3:50 pm |
|
|
PCM as always the genius you are, solved the problem.
Thanks a lot bud, I really appreciate it. Excuse my stupid code. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 01, 2006 3:54 pm |
|
|
It's not genius. I didn't expect code with that level of a mistake in it
so it took me a while to downshift mentally enough to see it. |
|
|
Guest
|
|
Posted: Thu Nov 02, 2006 6:03 am |
|
|
Hi,
As a side comment, the extra complication of the Input() statement got you into trouble during basic troubleshooting. In the future, I'd recommend that you reduce your test program to it's simplest form (lighting an LED, and then looping indefinitely, for example) to validate the basic functionality of your circuit. In your example, a very simple programmatical error forced you to conclude that your PIC was totally dead. That is a bad design!
Tim |
|
|
|