Hello richard,
I configured my code for 12 Bit AD, now I get 12 Bits results, but it is working only with 4MHz external oscillator.
When I replace extenal oscillator wit 20MHz and DEFINE OSC 20, it is not working, what is wrong?
Define LOADER_USED 1
DEFINE OSC 4
' Define LCD registers and bits
Define LCD_DREG PORTB
Define LCD_DBIT 4
Define LCD_RSREG PORTC
Define LCD_RSBIT 7
Define LCD_EREG PORTC
Define LCD_EBIT 6
DEFINE LCD_BITS 4 ' 4-bit data bus
DEFINE LCD_LINES 2 ' LCD - 2 lines
' Define ADCIN parameters
Define ADC_BITS 12 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
adval var word ' Create adval to store result
advalLow VAR WORD ' make it available to use in PBP
advalHigh VAR WORD ' make it available to use in PBP
advalLow = ADRESL
advalHigh = ADRESH
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00001010 ' Set PORTA analog...
ADCON2.7=1 ' ...and right justify result
Pause 500 ' Wait .5 second
loop: ADCIN 0, adval ' Read channel 0 to adval
adval = ADRESL + (ADRESH * 256)
Lcdout $fe, 1 ' Clear LCD
Lcdout "Value: ", DEC adval ' Display the decimal value
Pause 100 ' Wait .1 second
Goto loop ' Do it forever
End
Bookmarks