I have now combined the commands into one sub "Getmax1239" by putting the channel number it reads that channel eg Getmax1239 1 will read channel number one, the 12bits are stored in the global variable "Max1239b" ready to be worked with making it easy to replace the getadc() command.
Regards Paul
[code:1:4deeb3ac34]
'----this takes a channel number (Chno) sets up the ADC
'----tells it to do the conversion
'----and reads the value from the channel
Sub Getmax1239(byval Chno As Byte )
Local Scan_val As Byte
'--move the bits to the left one place as the last bit
'--is "1" as we are writing to the ADC
Shift Chno , Left , 1
'--&H61 is to read channel 0 so if we add
'--the channel number to it shifted left
'--one place we will get the byte to read
'--the channel number we want
Scan_val = &H61 + Chno
'use internal reference, internal clock, unipolar mode
I2csend Wrmax1238 , Setmax1238
I2csend Wrmax1238 , Scan_val
'--read in the two bytes using the overlay function
'--which breaks up the Max1239b word
I2creceive Rdmax1238 , Max1239lh(1)
I2creceive Rdmax1238 , Max1239lh(2)
'--move the word to the left 4 bits causing
'--the first 4 bits to get lost then move it
'--back 4 bits which will make them all 0s
'--giving us only the 12bits we want
Shift Max1239b , Left , 4
Shift Max1239b , Right , 4
End Sub
[/code:1:4deeb3ac34]
↧