PDA

View Full Version : Using the pic12F683



TonyA
- 4th April 2006, 19:40
Hi,

I am a little confused about how to set up the pic12F683, was wondering if some can offer some help. I'm using PicBasic Pro

I'm just using ANO-AN2 as analog inputs to read pots.
GP5 as an output to drive a speaker. (I'm using the SOUND command to make some noise).

This is what I have for the setup so far:

DEFINE OSC 8 'Oscillator speed in MHz
DEFINE ADC_BITS 10
DEFINE ADC_SAMPLEUS 50

OSCCON = %01110000 ' Set to 8MHz
CMCON0 = 7 ' Analog comparators off

ANSEL = %00000111 ' Set AN0-AN2 analog, rest digital

'And then my main code just does something like this:

main:

adcin 0, result 'read pot on pin

adcin 1, result1

adcin 2, result2

sound 5, [stuff] 'pin 2 is sound ouput

I was wondering if I have to also set up the TRISIO, and if I am missing anything else here.

I'm just piecing this togther for bits of code I find on the web, trying to make sense of it. Any help would be appreciated, thank you.

Tony A

Bruce
- 6th April 2006, 00:16
Hi Tony,

You don't necessarily have to set these pins to inputs with TRISIO before
using ADCIN, but it definitely is good practice to do so.

Pins are inputs by default at power-up, but I always include TRIS statements
in code just to be 100% sure the pin is an input before reading it.

TonyA
- 6th April 2006, 12:46
Thank you.

For this particular chip the ANSEL is used instead of ADCON1?

Would I still need to set up the ADCON0 if the ANSEL is set up?

Would you only disable the analog comparator when using a digital input?


Here's what I have now:

DEFINE OSC 8 'Oscillator speed in MHz
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 15
OSCCON = %01110000 ' Set internal OSC to 8MHz
ANSEL = %00001111 ' Set AN0-AN3 analog, rest digital
TRISIO.5 = 0 ' GP5 is output
ADCON0.7 = 1 ' Right justify for 10 bit result

INTCON = %00000000 'all interrupts OFF



Thanks again,
Tony



Hi Tony,

You don't necessarily have to set these pins to inputs with TRISIO before
using ADCIN, but it definitely is good practice to do so.

Pins are inputs by default at power-up, but I always include TRIS statements
in code just to be 100% sure the pin is an input before reading it.