Hi. I'm currently trying to interface with a serial DAC. I have 16 bist of data, and I want to send these MSB first to the DAC. My question is: How do I access the MSB of 2 bytes of data, and then shift the whole "row" of bits to the left so I can access the next MSB? Rotating or shifting in itself isn't a problem, but I need to shift the MSB of the second byte to the LSB position of the first byte aswell. Does anyone have a solution to this? Or maybe I'm just going about it in the wrong way. Are there any easier way of sending this data to my DAC (Considering I do not have an SPI or microwire interface as an on-chip peripheral)... Thanks for any help. Oyvind
I can't see a problem. There is a number of ways to do that.
extern void SendBit(bit b); void SendWord(int word) { unsigned int mask; for (mask=0x8000; mask; mask>>=1) { SendBit(word&mask); } } // or void SendWord(int word) { int i; for (i=0; i<16; i++) { SendBit(word&0x8000); word<<=1; } } // or void SendWord(int word) { int i; for (i=0; i<16; i++) { SendBit(word&0x8000); word=_irol_(word,1); // rotate instead of shifting } }
Ahh... I see it now. I was treating it as two separate bytes, while I of course have to just add it up to a word... I'll give that a try right away. Thank you VERY much for your help. I just love these message boards. Always someone there that can help you out with these silly (little) problems. Thanks again! Oyvind