Hello. This is my first question in this forum.
I have read it for some time. Thanks.
I need help with a code example for reading AN0,AN1,AN3 with 10bit result.
I have found som examples but they dont work.
My display show 1=0 2=0 3=random values. can some one tell me what i do wrong.
The hardware is ok. i use PBP247.
' Compiler : PICBASIC PRO Compiler 2.47
' Assembler : PM or MPASM
' Target PIC : 40-pin 16F887
' Oscillator : 4MHz external crystal
' Description : PICBASIC PRO program to display result of
' 10-bit A/D conversion on LCD
' Connect analog inputs to channels 0, 1, 3 (RA0, 1, 3)
' Define LCD registers and bits
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
' Define ADCIN parameters ********************************
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
'Define ADC_CLOCK 3 ' This define is inoperative on 16F88x
ADCON0 = %11000000 ' Set ADC_CLOCK to RC (DEFINE ACD_CLOCK inoperative on the 16F88x)
ADCON1 = %00000000 ' Left-Justify result in ADRESH:ADRESL registers
ANSEL = %00001011 ' Set AN0, AN1, AN3 to analog, others digital
ANSELH = %00000000 ' Set AN8 and higher channels to digital operation
'************************************************* *********
adval1 Var word ' Create adval1 to store result
adval2 Var word ' Create adval2 to store result
adval3 Var word ' Create adval3 to store result
TRISA = %11111111 ' Set PORTA to all input
Pause 500 ' Wait .5 second
mainloop:
Lcdout $fe, 1 ' Clear the LCD
Adcin 0, adval1 ' Read the first ADC channel
Lcdout "0=", #adval1 ' Send it to the LCD
pause 10
Adcin 1, adval2 ' Read the second ADC channel
Lcdout " 1=", #adval2 ' Send it to the LCD
pause 10
Adcin 3, adval3 ' Read the third ADC channel
Lcdout " 3=", #adval3 ' Send it to the LCD
Pause 200 ' Delay for time to read the display
high portd.1 'led detect program run
pause 200
low portd.1
Goto mainloop ' Do it forever
End
Bookmarks