scottl
- 25th June 2006, 17:52
Can someone see anything wrong with the following code? I can read GPIO.0 but when I try to read any other A/D I get nothing from any of the A/D. I am sure it is my code can someone help? If I can just get it to work I will clean up the code. The goal is the read GPIO.0 and GPIO.1 then subtract the lower from the higher. Any other suggestions?
@ device pic12F675,intrc_osc,wdt_off,protect_off,MCLR_off
dEFINE OSC 4 ' We're using a 4 MHz oscillator
DEFINE OSCCAL_1k 1 ' DEFINE OSCCAL FOR PIC12C671 or PIC12F675
adval VAR WORD 'Create adval to store result
adval1 VAR WORD 'Create adval to store result
adval_C VAR WORD 'Create adval_C for celsius Conversion
adval_F_18 VAR WORD 'Create adval_F for farenheit Conversion
adval_F_32 VAR WORD
sign var word
sign = "+"
check var byte
ANSEL = 49
CMCON=7
High GPIO.4
pause 5
low GPIO.4
pause 500
loop:
ADCON0 = %10000001 ' + (J*8) ' SET A/D Fosc/8 + A/D = ON
PAUSE 10 ' PAUSE 10mS FOR CHANNEL SETUP
adcin GPIO.0, adval
ADCON0 = %10000101
PAUSE 10 ' PAUSE 10mS FOR CHANNEL SETUP
adcin GPIO.1, adval1
adval = (adval * 5) / 10
adval1 = (adval1 * 5) / 10
if adval < adval1 then
adval_C = adval1 - adval
check = 1
else
adval_C = adval - adval1
check = 0
endif
if (check = 1) & (adval_C > 32) then
sign = "-"
else
sign = "+"
endif
adval_F_18 = (adval_C * 18)/10
adval_F_32 = (adval_F_18 + 32)
SerOut2 GPIO.5,84, [sign, DEC adval_F_32,13,10]
Pause 1000' Wait 1 seconds
GoTo loop
end
Thanks in advance,
Scott
@ device pic12F675,intrc_osc,wdt_off,protect_off,MCLR_off
dEFINE OSC 4 ' We're using a 4 MHz oscillator
DEFINE OSCCAL_1k 1 ' DEFINE OSCCAL FOR PIC12C671 or PIC12F675
adval VAR WORD 'Create adval to store result
adval1 VAR WORD 'Create adval to store result
adval_C VAR WORD 'Create adval_C for celsius Conversion
adval_F_18 VAR WORD 'Create adval_F for farenheit Conversion
adval_F_32 VAR WORD
sign var word
sign = "+"
check var byte
ANSEL = 49
CMCON=7
High GPIO.4
pause 5
low GPIO.4
pause 500
loop:
ADCON0 = %10000001 ' + (J*8) ' SET A/D Fosc/8 + A/D = ON
PAUSE 10 ' PAUSE 10mS FOR CHANNEL SETUP
adcin GPIO.0, adval
ADCON0 = %10000101
PAUSE 10 ' PAUSE 10mS FOR CHANNEL SETUP
adcin GPIO.1, adval1
adval = (adval * 5) / 10
adval1 = (adval1 * 5) / 10
if adval < adval1 then
adval_C = adval1 - adval
check = 1
else
adval_C = adval - adval1
check = 0
endif
if (check = 1) & (adval_C > 32) then
sign = "-"
else
sign = "+"
endif
adval_F_18 = (adval_C * 18)/10
adval_F_32 = (adval_F_18 + 32)
SerOut2 GPIO.5,84, [sign, DEC adval_F_32,13,10]
Pause 1000' Wait 1 seconds
GoTo loop
end
Thanks in advance,
Scott