【发布时间】:2013-01-27 06:08:55
【问题描述】:
我有一个关于屏蔽和位移的问题。
我有以下代码:
void WriteLCD(unsigned char word, unsigned commandType, unsigned usDelay)
{
// Most Significant Bits
// Need to do bit masking for upper nibble, and shift left by 8.
LCD_D = (LCD & 0x0FFF) | (word << 8);
EnableLCD(commandType, usDelay); // Send Data
// Least Significant Bits
// Need to do bit masking for lower nibble, and shift left by 12.
LCD_D = (LCD & 0x0FFF) | (word << 12);
EnableLCD(commandType, usDelay); // Send Data
}
“字”为 8 位,通过 4 位 LCD 接口输入。这意味着我必须在发送数据之前将最高有效位和最低有效位分开。
LCD_D 是一个 16 位数字,其中只有我传递给它的最高有效位我想要真正“做”一些事情。我希望保留之前的 12 位,以防他们在做其他事情。
就位掩码和“字”移位而言,我的逻辑在将上下半字节适当地传递给 LCD_D 方面是否正确?
感谢您的帮助!
【问题讨论】:
标签: bit-manipulation pic masking bit-shift lcd