In SX Microcontrollers, SX/B Compiler and SX-Key Tool, JonnyMac wrote: You'll have to 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 from one to the other -- this is tricky in high-level SX/B because the >> and << operators clear the Carry bit which is what we use 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 opeators you'll see that the Carry gets cleared first. This is why we have to shift and then copy a bit from one element to the other. In assembly, it's a little easier because the Carry helps us: [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#m327012 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)