Digitaldood
- 7th January 2013, 13:36
I am having a problem combining using ADC on channel A0 and saving data to a SEEPROM on portB.0 and 1. Individually I can get each to work, displaying the results on an LCD (on PortC). But when I try to combine them using the following code, I only get 255 read back as what is being stored in the SEEPROM (which is a 24LC512). But the Temperature readings are being read properly, which tells me I have the ADC part working, but not the I2C part. It seems as though the ADCON1 statement is what is causing it, but I don't know why that would have anything to do with I2C.
I am still learning, and I've looked for a similar program but could not find anything that resembles my program. Any help would be appreciated.
Thank you,
' Define A/D converter and LCD parameters
'
DEFINE ADC_BITS 8 ' A/D number of bits
DEFINE ADC_CLOCK 3 ' Use A/D internal RC clock
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
Define LCD_DREG PORTC
Define LCD_DBIT 4
Define LCD_RSREG PORTC
Define LCD_RSBIT 3
Define LCD_EREG PORTC
Define LCD_EBIT 2
'
' Variables used
'
Res Var Byte ' A/D converter result
Temp1 Var Byte ' Temperature in degrees F
Addr Var Byte ' Address of EEPROM
CPin var PortB.0 'Pin for the SEEPROM Clock
DPin var PortB.1 'Pin for the SEEPROM Data
I var byte 'Variable for Collecting Data For/Next Loop
RI var byte 'Variable for Results Reading For/Next Loop
WB var word 'Varable for Waiting for Button Loop
TRISB.7 = 1 'Pin used for Button
'
'
PAUSE 500 ' Wait 0.5sec for LCD to initialize
'
' Clear display and display message "COLLECTING DATA…"
'
lcdout 254,0
lcdout 254,1,"Collecting DATA>"
'
' Initialize the A/D converter
'
TRISA = %11111111
ADCON1 = %00000010
'==========================Colect Data======================================
CollectData:
FOR I = 0 TO 60
ADCIN 0, Res ' Read Channel 0 data
Temp1 = Res - 40 ' Calc Adjustment to degrees F
I2CWrite DPin,CPin,$A0,Addr,[Temp1]
lcdout 254,192,dec3 Addr, " : ", dec3 Temp1
PAUSE 10 ' Wait 1 msecond
gosub WaitForButton
NEXT I ' Repeat
lcdout 254,0
lcdout 254,1, "Results"
goto DoneCollecting
'===========================Wait For Button=================================
WaitForButton:
For WB = 1 to 600
if PortB.7 = 1 then Results
pause 10
Next WB
Return
'=============================Done Collecting================================
DoneCollecting:
if PortB.7 = 1 then Results
pause 10
goto DoneCollecting
'===============================Results=========== ==========================
Results:
lcdout 254,0
lcdout 254,1, "Results"
FOR RI = 0 TO 60
I2CRead DPin,CPin,$A0,Addr,[Temp1]
lcdout 254,192,dec3 Addr, " : ", dec3 Temp1
pause 1000 'Wait one second
NEXT RI
END ' End of program
I am still learning, and I've looked for a similar program but could not find anything that resembles my program. Any help would be appreciated.
Thank you,
' Define A/D converter and LCD parameters
'
DEFINE ADC_BITS 8 ' A/D number of bits
DEFINE ADC_CLOCK 3 ' Use A/D internal RC clock
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
Define LCD_DREG PORTC
Define LCD_DBIT 4
Define LCD_RSREG PORTC
Define LCD_RSBIT 3
Define LCD_EREG PORTC
Define LCD_EBIT 2
'
' Variables used
'
Res Var Byte ' A/D converter result
Temp1 Var Byte ' Temperature in degrees F
Addr Var Byte ' Address of EEPROM
CPin var PortB.0 'Pin for the SEEPROM Clock
DPin var PortB.1 'Pin for the SEEPROM Data
I var byte 'Variable for Collecting Data For/Next Loop
RI var byte 'Variable for Results Reading For/Next Loop
WB var word 'Varable for Waiting for Button Loop
TRISB.7 = 1 'Pin used for Button
'
'
PAUSE 500 ' Wait 0.5sec for LCD to initialize
'
' Clear display and display message "COLLECTING DATA…"
'
lcdout 254,0
lcdout 254,1,"Collecting DATA>"
'
' Initialize the A/D converter
'
TRISA = %11111111
ADCON1 = %00000010
'==========================Colect Data======================================
CollectData:
FOR I = 0 TO 60
ADCIN 0, Res ' Read Channel 0 data
Temp1 = Res - 40 ' Calc Adjustment to degrees F
I2CWrite DPin,CPin,$A0,Addr,[Temp1]
lcdout 254,192,dec3 Addr, " : ", dec3 Temp1
PAUSE 10 ' Wait 1 msecond
gosub WaitForButton
NEXT I ' Repeat
lcdout 254,0
lcdout 254,1, "Results"
goto DoneCollecting
'===========================Wait For Button=================================
WaitForButton:
For WB = 1 to 600
if PortB.7 = 1 then Results
pause 10
Next WB
Return
'=============================Done Collecting================================
DoneCollecting:
if PortB.7 = 1 then Results
pause 10
goto DoneCollecting
'===============================Results=========== ==========================
Results:
lcdout 254,0
lcdout 254,1, "Results"
FOR RI = 0 TO 60
I2CRead DPin,CPin,$A0,Addr,[Temp1]
lcdout 254,192,dec3 Addr, " : ", dec3 Temp1
pause 1000 'Wait one second
NEXT RI
END ' End of program