Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Programming PICC through MPLAB

Status
Not open for further replies.

MatrixPhreak

New Member
Hi, I'm new to the forums and haven't done much browsing around. But I've got a problem and I hope you can help me.

I've been trying, in vain, to program a PIC16F872 using Picc. First, my MPLAB says I don't have "PCM" installed, so it won't compile but I got around that by getting the CCS PICC Compiler.

Soooo, I throw my code into that, compile a .hex file, import that to MPLAB, hit program, and all seems to work right. Until I apply power to the circuit, however... at which point nothing happens. I've checked and rechecked the wiring, and the only thing that seems dubious is the clock (I'm using one of those two-pronged crystal oscillators and I'm a little confused over the placement of the capacitors).

If anyone could help me out by telling me how to wire that chip up or giving me just some simple sample code to test out, it would be much appreciated. Or, if it's a problem with how I'm sending code to the microcontroller, perhaps that could be fixed too?

Any help is appreciated, though... and thank you in advance
 
You don't mention what programmer you are using?.

But for a minimum PIC circuit, you could check my tutorial hardware, the 16F876 board should be identical to what you need.
 
Sorry about that....

I'm using Microchip's Picstart Pro

EDIT: Maybe it could be the clock setup, 'cause I've checked and rechecked my fuses and code. When using a 2-pronged oscillator (dunno how else to put it, those 2-legged silver cans), I have to use capacitors too, right? What setup does that need?
 
Last edited:
MatrixPhreak said:
Maybe it could be the clock setup, 'cause I've checked and rechecked my fuses and code. When using a 2-pronged oscillator (dunno how else to put it, those 2-legged silver cans), I have to use capacitors too, right? What setup does that need?
You need to look at the datasheet for your PIC for this section (the one for your PIC, not necessarily this one, tho they may be identical):
osc.jpg
 
Ok, I've gone and gotten the recommended capacitor values specifically as the datasheet tells me. I've wired everything like the datasheet tells me, with just a few questions. the MCLR/Vpp pin should be tied to +5V, right? Does anyone have a full schematic of just a simple LED blinking board?

I've basically devolved to simply trying to blink this LED as a test. Any sort of schematic or working sample picc code for the PIC16F872 would be veeerrrryyy helpful for debugging and fixing my setup.

I'm using the CCS Picc compiler to compile my C code, and MPLAB 7.6 to send the .hex to my mcu. I'm programming through the Microchip Picstart Plus (not upgraded yet).

I can provide my current code, if that'll help. I'm using an 8MHz crystal oscillator, if that makes a difference.
 
- can you readback your program from the chip?
- got your oscillator selection programmed right?
- if you're not sure about the external osc, use external rc, which might be simpler.
 
1- I've checked that a few times, and the program is always read successfully.
2- 8MHz should be HS, right? 'cause that's what the datasheet says and that's what I've set it as.
3- I've been thinking about that. For RC, what's a good value for the capacitor, and what do I set for #use DELAY in my code? All the datasheet tells me is >20pF for the capacitance, but how does increasing the capacitance change the startup time or the clock speed?

I'd like a little more information about the RC mode, if anyone can provide.
 
MatrixPhreak said:
The MCLR/Vpp pin should be tied to +5V, right?
Yes. Use a pullup resistor of 33K or so. The value is not critical.

Does anyone have a full schematic of just a simple LED blinking board?
Yes! And here's a simple blinky program to go with the schematic. And here's one more.

I'm using an 8MHz crystal oscillator, if that makes a difference.
It does. Those programs above assume 20MHz. One program blinks at 1Hz (once a second) and one blinks at 2Hz, I believe. But with a 8MHz crystal they're going to blink at less than half that rate.

But who cares! The important thing is that they blink the LED, so you can confirm that your PIC and circuit are working.
 
Well, I got back from Rat Shack, happy as a clam to have some new capacitors when, lo and behold...

My conversion was off in my head, and thinking .022uF = 22pF turns out to be a mistake and it would seem my clock problems continue.

It looked like, the only capacitor they carried in the pF scale was rated 100pF. I might've missed over something lower, but I'm not sure.

How much of a problem would it be to use 100pF in place of a 15pF:ltoet:x:ltoet:33pF recommended cap? would it be a problem? And if so, how well would a 100pF cap work in an RC setup, where it's only recommended to be >20pF?
 
MatrixPhreak said:
Well, I got back from Rat Shack, happy as a clam to have some new capacitors when, lo and behold...

My conversion was off in my head, and thinking .022uF = 22pF turns out to be a mistake and it would seem my clock problems continue.

It looked like, the only capacitor they carried in the pF scale was rated 100pF. I might've missed over something lower, but I'm not sure.

How much of a problem would it be to use 100pF in place of a 15pF:ltoet:x:ltoet:33pF recommended cap? would it be a problem? And if so, how well would a 100pF cap work in an RC setup, where it's only recommended to be >20pF?

Well, uF is 10^-6, nF is 10^-9, and pF is 10^-12, so 0.022uF is 22nF, or 22000pF

The 'metal can with 2 leads' is a crystal, and it probably won't start up with 100pF. Don't confuse a crystal oscillator with an RC, they are very different. With an RC osc. the cap charges through the resistor, so using a cap which is five times as large, would take five times as long to charge.

I don't think you have told us what PIC you are using; some have internal oscillators, which don't need anything other than configuration, and may be a better choice for you.
 
BeeBop said:
Well, uF is 10^-6, nF is 10^-9, and pF is 10^-12, so 0.022uF is 22nF, or 22000pF

The 'metal can with 2 leads' is a crystal, and it probably won't start up with 100pF. Don't confuse a crystal oscillator with an RC, they are very different. With an RC osc. the cap charges through the resistor, so using a cap which is five times as large, would take five times as long to charge.

I don't think you have told us what PIC you are using; some have internal oscillators, which don't need anything other than configuration, and may be a better choice for you.

Yeah, I know what a crystal is. And I know the difference between that and the RC mode as I've tried both modes and am most definitely not confusing the two. So thank you for your condescending pseudo-help there. But other than that, thank you sincerely for letting me know that substitution isn't as flexible as I would've hoped.

And I've said my PIC twice in this thread, once at the very beginning and once a post or two down from there. But I'll restate: I am trying to program a PIC16F872. I'm checking through the datasheet right now, but I don't think it supports internal oscillation; however, if anyone knows otherwise and can help me through it, it'd be easier than digging through the PDF over and over again.
 
Geesh MatrixPhreak, you don't need to be nasty. The guy was just trying to help. He doesn't necessarily know how much you know or don't know. Better to err on the side of newbieness just in case, so you don't have to go over it twice.

Lighten up, dude! :D
 
I didn't mean to be condescending, there is no need to get defensive; I was trying to help you. When you said:
When using a 2-pronged oscillator (dunno how else to put it, those 2-legged silver cans), I have to use capacitors too, right? What setup does that need?
it seemed that you didn't know the difference between a crystal, and an oscillator, then you start in talking about an RC oscillator....

And I've said my PIC twice in this thread, once at the very beginning and once a post or two down from there. But I'll restate: I am trying to program a PIC16F872. I'm checking through the datasheet right now, but I don't think it supports internal oscillation; however, if anyone knows otherwise and can help me through it, it'd be easier than digging through the PDF over and over again.

Sorry, I didn't see that. Perhaps digging through that data sheet would be good for you, however you are correct. The 'F872 doesn't have an internal oscillator.

If you don't have access to components other than mail order, you might try an RC circuit. Microchip recommends charging a greater than 20pF cap through a minimum 3k resistor. If all you have is a 100pF, you could charge it through a 3k resistor which would give you an idea that your cct. was working.
 
Last edited:
Sorry, sorry, I was a bit quick to jump at it. I didn't mean to seem nasty either, which I guess is probably misconceived through the same fault I ran into... which is to say the internet and text-only interaction makes it really hard to judge the tone of something. I'm heading back to Rat Shack tonight to pick through their bins and see what they have, I'll also be taking a trip to the ECE stockroom here at school.

Sorry again for snapping at you
 
It is only words, and I know you are frustrated with the thing, so I didn't take your words to heart. Good luck finding what you need at the ratshack.
 
Well, the components work!

What I'm having trouble with now, is:

What might the picc code be for recognizing a button push? Right now I've got
Code:
while(1){
   while(!input(PIN_A0)){
      output_low(PIN_B6);
   }
   output_high(PIN_B6);
   }
Which should, in my messed up theory, have pin B6 low until the button tied to A0 is pressed, and then it sets pin B6 high.

HOWEVER, it doesn't seem that that code is working like I'd hoped. Could anyone set me right?
 
MatrixPhreak said:
Well, the components work!

Code:
while(1){
   while(!input(PIN_A0)){
      output_low(PIN_B6);
   }
   output_high(PIN_B6);
   }

Simpler way to express that:
Code:
while (1)
{
  if (input(PIN_A0))
  {
      output_low(PIN_B6);
  }
  else
  {
      output_high(PIN_B6);
  }
}
But your version should work too.
 
Well guys, I dunno if this is normal or if this is totally a lack of good wiring...

but, it would seem that my circuit is quite sensitive to air-capacitance. In fact... the LED lights until anything comes near it. Then, at a certain radius that seems constant, it shuts off until the hand is moved away.

Is this normal? 'cause it doesn't seem like it...
 
Status
Not open for further replies.

Latest threads

Back
Top