In SX Microcontrollers, SX/B Compiler and SX-Key Tool, JonnyMac wrote: You'll could synthesize a 24-bit value from a byte and a Word. Let's say you do this: [code]calHigh VAR Byte ' bits 16 - 23 calLow VAR Word ' bits 0 - 15[/code] The trick is shifting a bit from one element to the other -- this is problematic in high-level SX/B because the >> and << operators clear the Carry bit which is what the SX uses to get a bit from one byte to the next. Let's assume the values are arriving MSB-first after the clock line goes high. You might have a loop like this: [code]Get_Cal_Bits: FOR idx = 0 TO 23 DO WHILE ClockPin = 0 LOOP calHigh = calHigh << 1 calHigh.0 = calLow.15 calLow = calLow << 1 calLow.0 = DataPin DO WHILE ClockPin = 1 LOOP NEXT[/code] If you look at the compiler output for the shift operators you'll see that the Carry gets cleared first (this is why we get a 0 in the LSBit for << or the MSBit for >>). The "shifty" lines above compile to the equivalent of this: [code]ASM CLC RL calHigh MOVB calHigh.0, calLow_MSB.7 CLC RL calLow_LSB RL calLow_MSB MOVB calLow_LSB.0, DataPin ENDASM[/code] The CLC instruction means CLear Carry. This is why -- with high-level SX/B -- we have to shift and then copy a bit from one element to the other. If we code this "shifty" stuff in Assembly we can use the Carry to our advantage: [code]Get_Cal_Bits: FOR idx = 0 TO 23 ASM JNB ClockPin, @$ MOVB C, DataPin RL calLow_LSB RL calLow_MSB RL calHigh JB ClockPin, @$ ENDASM NEXT[/code] As you can see, we copy the Data pin into the Carry bit and the the left shift (RL) instructions move everything through (right to left). I don't know if this will help you but, perhaps, it will give you some insight into getting 24 bits from the caliper. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=326798#m327018 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)