Crazy stuff happening with my 16F877A. I can program it fine, and it runs. Right now it's running a program that blinks an LED, connected to port B, every few seconds. When I put my hands near the LED, the PIC, or even the metal backplate of my breadboard, the LED starts flickering crazy fast. Clearly, I'm altering the capacitance of something in the circuit, and my guess is it's messing up the clock somehow. I'm using a 12 MHz crystal and two 22pF ceramic disc caps. I've tried quiet a few other crystals, too, and none of them make a difference. I do have the PIC's oscillator set in HS mode. Oh, and here's something else for you. When I unplug my PICkit 2 from the circuit, the PIC ceases to work at all. And yes, it is powered externally. What the hell is going on?
Take a gooooood look at your MCLR pin. Is it setup correctly? Does it have a 10k resistor to pull-up to +5V? Or do you have the internal weak pullup enabled? The only trouble with the internal pullup, is that some programmers prefer this not to be enabled. Likewise, check you don't have any external pin interupts floating.
Also check PGM is pulled low or LVP disabled in your config word, as this will do funny stuff in the same way leaving MCLR floating does.
isn't the PGM pin multiplexed on the 887A? As long as you pull-up the MCLR pin the PGM pin is just fine I guess... It's just what Macaba said... the things I forgot for quite a long time too... the MCLR pin making the led flicker, and the external interrupts stopping my chip completely
Uhh, no No, you have to pull PGM low if LVP is enabled, which by default it is, and is something newcomers forget to disable in the config word.
Is there, like, any information on this stuff? I've read quite a few tutorials and none of them mentioned this stuff. And by information I do not mean page 254 of 642 in a cryptic datasheet.
The datasheets can be like an epiphany, you'll read the whole thing cover to cover. Then 3 months later, you'll have a problem. Of course, the solution to the problem is in the datasheet in one of those sections you just glossed over. Welcome to datasheet world! Seriously, steveyG is totally correct about microchip having some of the best datasheets, failing that, the microchip forum is good too. I havn't really had any 'doh ray me' moments. The only things that I have found out through knowledgable people, that would have otherwise really stumped me is the fact that the upper bits of the PC counter don't increment when doing a table lookup in a different 'page'. At least, i think thats how you describe it technically. So you have to change the bits yourself.
You're right, they are good datasheets, but they aren't particularly suited for beginners. And they shouldn't be, since they're datasheets.
heres some stuff from my classes, don't know if it has what you need, but it is on the 16f877 specifically: link i have all my lab code saved as well... edit: heres a schematic of the boards we used to program them
I pulled MCLR high and PGM low. With PGM low, the LED is constantly on instead of blinking. I tied a bunch of other stuff low, too, and it didn't help. With the PK2 connected, it's a lot less sensitive. I tried pulling PGC and PGD both high and low, since the PK2 connects to those, with little no change. Whatever the problem is, I think it's on the right side of the PIC, since moving my hand there makes it go nuts, but not the left side. I'd think there are some pins floating there that are messing things up, but I've tried tying everything high and low with no help. I should probably read the datasheet. In the meantime, any suggestions?
Can you post your code please. With PGM low and the LED constantly on, your PIC must be running because a pin can't be pulled high while the PIC isn't running (unless it's stalled). What decoupling do you have on your board?
Although PIC's are pretty resilient, i've burnt out a few in my time. Have you tried programming a different 16F877A?
Uh oh, you're not going to like this. I'm using the HI-TECH PICC compiler at the moment. Please, no lectures, I'm well aware of the pros and cons of assembly and high level languages on small-scale embedded devices. Code: #include <pic.h> /* * Demo program * * Flashes LEDs on Port B, responds to switch press * on RA1. Usable on PICDEM board. * * Copyright (C)1997 HI-TECH Software. * Freely distributable. */ #define BUTTON RC1 //bit 1 of PORTC main(void) { unsigned char i, j; TRISB = 0x10000000; j = 0; for(;;) { PORTB = 0x10000000; for(i = 100 ; --i ;) continue; PORTB = ~j; /* output value of j */ for(i = 100 ; --i ;) continue; if(BUTTON == 0) /* if switch pressed, increment */ j++; } } I've had simpler assembly programs before, they acted the same way. None. Should I? It's running off of an ATX power supply turned bench supply.
Its amazing how much a difference having a decoupling capacitor near the pins of the IC makes on any supply. Although I'm not sure how it could be the cause of your problems, i'd do it anyway.
Definitely, you want decoupling caps, ATX power supplies are switching power supplies, so they will always have some noise in them. Plus how long are the wires your using from the PSU to the project board? Are they a twisted pair? if not then they can pick up noise easily. Now I'm not saying you should use shielded twisted pair for all your power wire, though that would be good. But decoupliung caps right at the device are always a good idea. On the 877A you can take a 806 or 1206 size SMD capacitor and solder it right onto the solder pads for Vss and Vcc pins. Or if your using a socket, you can put a small ceramic cap underneath of it. Along with your pull up resistor for MCLR.