Shifting bits on an M2

NVHLVNOP

Member
Hi, I need to shift bits around on an M2 chip. The <<, >>, setbit, and clearbit commands work only on X2 chips. How can I get around this? More specifically here's what I need to do...

I have the following 8-bit value: %11100111 (it's actually stored in a word variable so really it is %0000000011100111)
I need to pretend it's a 10-bit value and split it up to two bytes and left-justify it to %00111001 and %11xxxxxx

The accepted format for the two bytes to send is b15,b14,b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,b2,b1,b0, where the 10 bit value is stored in b6 thru b15. b0 thru b5 are "don't care" bits.

This is for a 10-bit DAC chip that works on i2c. After addressing the chip I need to send it two consecutive bytes for the value I want to write into it.

The datasheet is 15mb, too large to attach, but if you want, you can see page 52 in the MCP4706/4716/4726 datasheet if the above does not make sense.

I looking for a way to create the two bytes from the one byte I have.

Thanks in advance!
 

AllyCat

Senior Member
Hi,

You might kick yourself:

w1 = w1 * 64 , then send b2 and b3 (or vice versa) ;)

In PICaxe terms it's not even much slower than <<

Cheers, Alan.
 
Top