I bet you thought I'd left the Country the time this one has taken me. I must admit I really confused myself at times and went around in circles a little (ok, a lot).
Anyway I think I've managed to convert mackrackit's 8bit ADC to a 10bit for the 16F684. I would be very interested to hear how I've done on this one. Seems to work, or have I just 'lucked in'?
Code:
DEFINE OSC 4
@DEVICE_INTRC_OSC_NOCLKOUT
@DEVICE_WDT_ON
@DEVICE_MCLRE_OFF
@DEVICE_CP_OFF
ANSEL = %00000001 'CHANNEL AN0
ADCON1 = %01010000 'FOSC/16
TRISA = %00000001 'AN0_Input Pin
CMCON0 = %00000111 'COMPARATORS OFF.
CHAN0 VAR word 'VAR TO HOLD ADC0N READING (10-BIT)
CHECK:
GOSUB ADC_0
GOSUB BLINK
GOTO CHECK
BLINK:
SELECT CASE CHAN0
CASE IS > 64
TRISA = %11001111
PORTA = %00010000
CASE ELSE
PORTA = %00000000
END SELECT
RETURN
ADC_0: 'READ AN0
ADCON0 = %10000001 'BIT0=ADC ENABLE: BIT1=A/D CONVERSION STATUS BIT
'BITS2-4=AN0 CHANNEL SELECT BIT(CHS0): ADFM BIT1= right justified
GOSUB READ_AD
CHAN0.highbyte = ADRESH 'A/D HIGHBYTE
CHAN0.LOWBYTE = ADRESL 'A/D LOWBYTE
RETURN
READ_AD: 'START THE ADC CONVERSION
PAUSE 50
ADCON0.1=1 '1 = A/D conversion cycle in progress.
'Setting this bit starts an A/D conversion cycle.
WHILE ADCON0.1=1:WEND 'Do WHILE condition is TRUE (I like WEND!).
RETURN
Dave
Bookmarks