bit manipulation - PIC Bit Masking and Shifting for 4 Bit LCD Control -



bit manipulation - PIC Bit Masking and Shifting for 4 Bit LCD Control -

i have question regarding both masking , bit shifting.

i have next code:

void writelcd(unsigned char word, unsigned commandtype, unsigned usdelay) { // important bits // need bit masking upper nibble, , shift left 8. lcd_d = (lcd & 0x0fff) | (word << 8); enablelcd(commandtype, usdelay); // send info // to the lowest degree important bits // need bit masking lower nibble, , shift left 12. lcd_d = (lcd & 0x0fff) | (word << 12); enablelcd(commandtype, usdelay); // send info }

the "word" 8 bits, , beingness set through 4 bit lcd interface. meaning have break important bits , to the lowest degree important bits apart before send data.

lcd_d 16 bit number, in important bits pass want "do" something. want previous 12 bits preserved in case doing else.

is logic in terms of bit masking , shifting "word" right in terms of passing upper , lower nibbles appropriately lcd_d?

thanks help!

looks ok apart needing cast "word" unsigned short (16 bit) before shift, in both cases, shift not performed on char , looses data. eg:

lcd_d = (lcd & 0x0fff) | ((unsigned short) word << 8);

bit-manipulation pic masking bit-shift lcd

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -