Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20562

BASCOM Project Blog : Working With MAX1238/9 12BIT 12 Channel I2C ADC : REPLY

$
0
0
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]

Viewing all articles
Browse latest Browse all 20562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>