PDA

View Full Version : Pic16f870



plyrathrt
- 1st August 2008, 17:47
I am new to using the PIC Mid-Range MCU's and I am struggling with them.

I can't seem to get the PIC16F870 to change it's pins to digital. I am only familar with PICBasic Pro.

Anyhow, from the datasheet and the reference manual for mid-range pic's, it seems that it uses ADCON0 and ADCON1. I have set these bits and my Tris bits. Still doesn't Fing work.

I have Porta.0, Porta.1, Portb.4, and Portb.5 as digital inputs (for a button press) and all the rest just need to be digital outputs so they can go high or low to switch some NPN transistors on and off.

Any help on how the hell to get this to function at all would be very appreciated.

skimask
- 1st August 2008, 17:50
And what values are you using for the ADCON registers and for the TRIS registers?

Straight from the PIC16F870 datasheet, DS30569B, Pg 80, and DS30569B, Pg 33, Para. 4.1., Register 10-2.

mat janssen
- 1st August 2008, 17:53
ADCON1 = 7

should be there to set all to digital.
I'ts all readable in the datasheet of that part.

plyrathrt
- 1st August 2008, 17:53
Adcon0=0
Adcon1=7
Trisa = %000011
Trisb = %00110000
Trisc = %00000000

This is what I have been using since the beginning and it still doesn't work. I have it on my EasyPIC 5 and when I load a simple code to blink LED's when I "press" one of the 4 inputs buttons, it doesn't blink any of the LEDs..... Very strange, Very confusing, and this chip is going to die via a hammer very soon.

skimask
- 1st August 2008, 18:22
Adcon0=0
Adcon1=7
Trisa = %000011
Trisb = %00110000
Trisc = %00000000

This is what I have been using since the beginning and it still doesn't work. I have it on my EasyPIC 5 and when I load a simple code to blink LED's when I "press" one of the 4 inputs buttons, it doesn't blink any of the LEDs..... Very strange, Very confusing, and this chip is going to die via a hammer very soon.

What happens if you load code just to blink LEDs without any button presses at all...just set all of the pins to outputs and blink them all...

plyrathrt
- 1st August 2008, 18:32
lol.... Not a damn thing. Not 1 pin goes high.

I have a few of these chips ordered at different times so the likely hood of all of them being bad is not very likely.

Edited:
I took out my "DEFINE OSC 8" and no Porta.6 goes high but is not blinking. So I guess it's still "nothing happens"..................

skimask
- 1st August 2008, 18:41
lol.... Not a damn thing. Not 1 pin goes high.
I have a few of these chips ordered at different times so the likely hood of all of them being bad is not very likely.
Edited:
I took out my "DEFINE OSC 8" and no Porta.6 goes high but is not blinking. So I guess it's still "nothing happens"..................
Kinda rules out bad port settings eh?


What are you using for an oscillator? A crystal? A resonator? External clock input?

Got a pull up on MCLR?

plyrathrt
- 1st August 2008, 18:55
Internal, packaged in to the chip.

You only need to pull up the MCLR for Programming... Also keep in mind, this is on a full development board (Mikroelectronica EasyPIC 5) and not just placed in a breadboard with ICSP.

skimask
- 1st August 2008, 19:01
Internal, packaged in to the chip.
You only need to pull up the MCLR for Programming... Also keep in mind, this is on a full development board (Mikroelectronica EasyPIC 5) and not just placed in a breadboard with ICSP.
Ok, here's the next question....and it's going to be a tough one, I mean hard...You may have to study quite awhile to answer this one...

Which internal clock would that be on the PIC16F870?
(Ref: Pic16F870 datasheet, DS30569B-page 89)

plyrathrt
- 1st August 2008, 19:17
I don't see anything about a software selectable internal oscillator. I am guessing that is why you said "you may have to study very hard". Is that correct?

Even with that it should still turn a pin high that I designate for a button press right?

skimask
- 1st August 2008, 19:33
I don't see anything about a software selectable internal oscillator. I am guessing that is why you said "you may have to study very hard". Is that correct?

Even with that it should still turn a pin high that I designate for a button press right?

Not without some sort of oscillator driving the chip you won't...The PIC16F870 doesn't have an internal oscillator...Therefore, your chip won't run anything.

Did you see the 4 oscillator/clock options you have with the PIC16F870?

plyrathrt
- 1st August 2008, 20:06
Yes I did, however for my project I must have a internal oscillator due to size constraints... Ok, so basicly I am the idiot and I should take a hammer to my head instead of the chip... I don't know why I assumed it had a internal oscillator other than the fact that I have never used mid-range MCU's. Only 16pin and smaller PIC's.

Know of a 28pin PIC with a accurate internal oscillator off the top of your head?

skimask
- 1st August 2008, 20:26
Yes I did, however for my project I must have a internal oscillator due to size constraints... Ok, so basicly I am the idiot and I should take a hammer to my head instead of the chip... I don't know why I assumed it had a internal oscillator other than the fact that I have never used mid-range MCU's. Only 16pin and smaller PIC's.

Know of a 28pin PIC with a accurate internal oscillator off the top of your head?

Parametric search at Microchip.com
13 hits on a 16F PIC in a 28 pin package with an internal oscillator block...
My personal favorite for a 28 pin PIC at the moment wouldn't be a 16F though. It would be a PIC18F2685 (96K of code space) or a PIC18F2550 (USB included)...
All sorts of options here...

Another thing...just to verify it all, get it to at least work, you can use the R/C oscillator. Just hang a resistor and a capacitor off the OSC1 pin and see what happens.
Sure, it's not accurate, but it'll at least verify that your hardware is good.

plyrathrt
- 2nd August 2008, 05:04
I just switched to a 16F690 that I had a PDIP version of as well as a SOIC version. It's a few pins short of what I need but it's fine for testing the final product and the most important thing is, it has a internal oscillator :-)

I really can't believe I overlooked that and wasted my time and everyone else in here. lol

I am etching the new prototype board out now after I tested the code working on my development board. Hopefully all goes well!

Thanks again for your help everyone!