Hi Melanie,
First of all thanks for your reply. I really appreciate it.
Attached is the schematic. The problem happens at PortA.4. However I already connect the incoming signal to PortB.7 and it is working.
Include "modedefs.bas"
Define OSC 8
Disable Interrupt 'to disable the interrupt bcoz the PortB.0 is in used
define INTRC_OSC, CCPMX_OFF, MCLR_OFF, LVP_OFF, PROTECT_ON
define MCLR_OFF, LVP_OFF
'@ __CONFIG _CONFIG1, _INTRC_OSC_NOCLKOUT&_CP_ALL
@ __CONFIG _CONFIG1, _CCP1_RB3
OSCCON = %01111110 ' 8 MHz, primary clock, internal RC
PIR1 = %00000000 ' clear all flags particularly A/D IF bit 6
SSPCON = %00000000
SSPBUF = %00000000
TXSTA = %00000000
RCSTA = %00000000
OPTION_REG.7 = 0 'weak pullups enable
'pin IO 76543210
TrisB = %10000100
TrisA = %01010101
cmcon =7 'disable the comparator register
ANSEL=%01010100'only the RA4/AN4, RA2/AN2, RB7/AN6 as analog input
ADCON1 = %10000000 ' right justified, AD Clock divided by 2,Vdd = Vref+, Vss = Vref-
CCP1CON = %00001100
CurrentLevelSensor con %00100000 'PortA.4/AN4
WaterLevelSensor con %00010000 'PortA.2/AN2
Start:
ADCON0 = OX2Input
gosub readadc
pauseus 60
Goto Start
'---------------read the ADC here ----------------------------------------
ReadADC:
ox2Result = 0
ADCON0.bit0 =1
'Pauseus 150 'can try 50 ~ 200us
Pause 250
'start the convertion here
ADCON0.bit2 = 1
while ADCON0.bit2 = 1
wend
ox2Result.Lowbyte = ADRESL
ox2Result.highbyte = ADRESH
return
'----------------------------




Bookmarks