View previous topic :: View next topic |
Author |
Message |
Silverback01
Joined: 30 Sep 2008 Posts: 11
|
Problem Programming 16F876A on Toshiba Satellite Laptop |
Posted: Mon Oct 06, 2008 7:45 pm |
|
|
I'm having serious issues trying to program a 16F876A with even the simplest code:
Code: |
#include <16F876a.h>
#fuses HS,NOWDT,PUT,NOLVP
#use delay(clock=20000000)
#define G_LED PIN_B5
#define BUTTON PIN_A1
void main(void)
{
while(1)
{
if(!input(BUTTON))
{
output_high(G_LED);
}
else
{
output_low(G_LED);
}
}
}
|
I know it's a hardware issue because the code is simple...Just turn on a LED when I push a button and make it go off when I release the button. It has also worked when programmed with a desktop computer in another building. It was recently suggested that laptop USB ports aren't the greatest and dirty power could be a problem. Another suggestion was that I might be receiving external electromagnetic interference from somewhere. The only transmissions nearby are wireless routers.
I am using a Toshiba Satellite laptop, a USB PICKit 2, and a 16F876A. I first used a solderless breadboard, but switched to a working homemade programming board, and even switched the chips out. When I take the same code into another building and program it on a desktop everything seems to work just fine.
The problems I have encountered range from the LED being on constantly, and when I push the button it gets brighter, or turns off. The last time I wrote to the chip, absolutely nothing happend.
Has anyone had a problem like this...Any suggestions?
Thank you,
John _________________ John |
|
|
crystal_lattice
Joined: 13 Jun 2006 Posts: 164
|
|
Posted: Tue Oct 07, 2008 1:18 am |
|
|
I can't say for sure what your problem is, I use a Dell D620 laptop with a usb => serial converter and ICD1 and have programmed hundreds of times without problems, until recently, I had to make a quick fix alarm system for my car.
I used a 16F876 and also experienced some strange errors. From code not executing to erratic behavior, to finally no response. I ended up reloading the firmware (i'm using the tiny bootloader.) while in the car and now it is working, although it worked fine for hours on the test bench with lots more sources of interference.
Maybe there is some problems with the silicon, my chip was sampled quit some time ago, so not sure what the chances are it being from the same batch... |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Tue Oct 07, 2008 7:30 am |
|
|
What I'm not seeing in the code is any kind of setup for the TRIS registers. I always do that (and I always use fast_io) so it looks like something's missing, to me.
Also, exactly what is connected to the input pin when you push the button, versus when you don't? If it's a contact closure to ground, you'd need a pullup to Vcc. If you used a pin of port B instead of port A, you could make use of the chip's internal pullups. But if all that's happening is a connection to ground, you'd be likely to get erratic operation, or no operation. |
|
|
Silverback01
Joined: 30 Sep 2008 Posts: 11
|
|
Posted: Tue Oct 07, 2008 8:59 am |
|
|
Since I'm just getting into this stuff, I'm working with the simplest code I can get away with. Especially since I can't get two working uploads in a row. Do you think the TRIS register setup and fast_io would help?
When the button is pressed there is a connection to ground. There is also a pullup resistor on it. _________________ John |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Tue Oct 07, 2008 9:53 am |
|
|
John P wrote: | What I'm not seeing in the code is any kind of setup for the TRIS registers. I always do that (and I always use fast_io) so it looks like something's missing, to me. |
Fast_io and manually setting the TRIS registers is RARELY needed with CCS. I used it once a few years ago when I needed precise microsecond pulse timing, but not in dozens of projects since.
It sounds like you have a shaky power supply or a bad ground connection. You might try working through a powered USB hub. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Silverback01
Joined: 30 Sep 2008 Posts: 11
|
|
Posted: Tue Oct 07, 2008 12:02 pm |
|
|
Well, I attached a 6-wire cable from the PICKit 2 to the programming board. Everything seems to be working just fine. I still have no idea what was wrong. Maybe it was just a loose connection or maybe the planets aligned just right.
Thanks! _________________ John |
|
|
Silverback01
Joined: 30 Sep 2008 Posts: 11
|
|
Posted: Thu Oct 09, 2008 8:39 pm |
|
|
I figured out what the problem was. For some reason the laptop seems to be the issue. I haven't figured out what is wrong with it, but I switched to a desktop and things seem to be working. _________________ John |
|
|
|