PDA

View Full Version : 16F88 reading Analog Input



thunderstrike44
- 27th August 2004, 18:22
Hi,

I have used the 16F877 PIC Processor for about a year and I have a little project I wanted to use the 16F88 for. I am having problems reading the analog inputs, I think. I have setup for only AN0 and AN1 to be analog in and am setting Port b 0-3 as indicators to see voltage level vdd-vss. Here is my testing code but I can't see to get it to work.

DEFINE LOADER_USED 1

OSCCON = %01100111

TRISA = %00000011
TRISB = %00000000
PORTB = %00000000

ANSEL = %00000011
ADCON1 = %10000000
CMCON = 7

DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50


CTA VAR BYTE

main:

ADCIN 0, CTA

ledtst1:
IF CTA > 50 Then tst2
PORTB = %00000001
GoTo cont

tst2:
IF CTA > 125 Then tst3
PORTB = %00000011
GoTo cont

tst3:
IF CTA > 200 Then tst4
PORTB = %00000111
GoTo cont

tst4:
PORTB = %00001111

cont:

Pause 10

GoTo main
End

It does not give me any errors nor does it work. I am using MELabs Pro Basic compiler version 2.44. I have ordered the 2.45 but have not gotten it yet.

Any sugguestions?

Thanks,
Brian

paul farrugia
- 30th August 2004, 10:58
Hi,
I,ve not used it either but a quick scan of the datasheet seems to show that ADCON0 must also be set?
Cheers
Paul

thunderstrike44
- 30th August 2004, 22:41
Tried that also to no avail. I don't know why they have to change the structure so much for one chip. I have been using the analog inputs on the 16F877A with out a problem, but the bugger is really different. There must be a answer.

Brian R.