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

BASCOM-AVR : how to assembled a three bye array in one data type : REPLY

$
0
0
Hello Aliahmad Bascom can convert it for you First you need a variable big enough to hold the bits as you have 24 you need a Long (Longs are stored as signed 32-bit binary numbers) so dim Xyz as long 'here we have 32 bits dim a(4) as byte at Xyz Overlay ' This breaks up the Xyz into 4 bytes 'this gets 3 bytes but you may find the order is reversed so you may have to swap some of the bytes around 'or just get one at a time with I2CRBYTE I2creceive &H9F , Lm75temp , 0 , 3 Shift Xyz , Right , 8 'move the bytes to the right we now have the value that Bascom knows Note if its negative you must first check if the first bit is one then pad the 8 bits in front with 1s See my code below using 12 bits from LM75a temperature IC Regards Paul [code:1:87c3904a61] 'Read Temperature Sub Lm75read Local Lm75temp As Integer I2csend &H9E , 0 I2creceive &H9F , Lm75temp , 0 , 2 Swap Lm75temp 'swap the bytes as I2creceive reverses them If Lm75temp.15 = 1 Then 'its a negative number Shift Lm75temp , Right , 5 ' 5 unused bits plus the sign bit above 'as its a neagative number the first 5 bits are "1" Toggle Lm75temp.15 Toggle Lm75temp.14 Toggle Lm75temp.13 Toggle Lm75temp.12 Else 'its a positive number Shift Lm75temp , Right , 5 ' 5 unused bits plus the sign bit above End If Lm75temp3 = Lm75temp * 0.125 'now we have the binary value End Sub [/code:1:87c3904a61]

Viewing all articles
Browse latest Browse all 20900

Trending Articles



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