US_CR = (1 << 2) | /* RSTRX: Reset Receiver: 1 = The receiver logic is reset. */
(1 << 3); /* RSTTX: Reset Transmitter: 1 = The transmitter logic is reset. */
US_CR = (0 << 2) | /* RSTRX: Reset Receiver: 1 = The receiver logic is reset. */
(0 << 3) | /* RSTTX: Reset Transmitter: 1 = The transmitter logic is reset.*/
(1 << 4) | /* RXEN: Receiver Enable: 1 = The receiver is enabled if RXDIS is 0. */
(0 << 5) | /* RXDIS: Receiver Disable: 0 = Noeffect. */
(1 << 6) | /* TXEN: Transmitter Enable: 1 = The transmitter is enabled if TXDIS is 0. */
(0 << 7) | /* TXDIS: Transmitter Disable: 0 = Noeffect. */
(1 << 8) | /* RSTSTA: Reset Status Bits: 1 = Resets the status bits PARE, FRAME, OVRE and RXBRK in the US_CSR. */
(0 << 9) | /* STTBRK: Start Break: 0 = Noeffect. */
(0 << 10) | /* STPBRK: Stop Break: 0 = Noeffect. */
(0 << 11) | /* STTTO: Start Time-out: 0 = Noeffect. */
(0 << 12);
这段程序是什么意思?
如果US_CR的初值是:0x00801A1A,执行完这段程序后,US_CR的值是多少?是怎么得来的?请解答一下好吗,谢谢了!
1<<2可以看作 SETB(US_CR^bit2),
初值对结果没有影响,结果是0x150。
US_CR = (1 < < 2) ? /* RSTRX: Reset Receiver: 1 = The receiver logic is reset. */
(1 < < 3); /* RSTTX: Reset Transmitter: 1 = The transmitter logic is reset. */
US_CR = (0 < < 2) ? /* RSTRX: Reset Receiver: 1 = The receiver logic is reset. */
(0 < < 3) ? /* RSTTX: Reset Transmitter: 1 = The transmitter logic is reset.*/
(1 < < 4) ? /* RXEN: Receiver Enable: 1 = The receiver is enabled if RXDIS is 0. */
(0 < < 5) ? /* RXDIS: Receiver Disable: 0 = Noeffect. */
(1 < < 6) ? /* TXEN: Transmitter Enable: 1 = The transmitter is enabled if TXDIS is 0. */
(0 < < 7) ? /* TXDIS: Transmitter Disable: 0 = Noeffect. */
(1 < < 8) ? /* RSTSTA: Reset Status Bits: 1 = Resets the status bits PARE, FRAME, OVRE and RXBRK in the US_CSR. */
(0 < < 9) ? /* STTBRK: Start Break: 0 = Noeffect. */
(0 < < 10) ? /* STPBRK: Stop Break: 0 = Noeffect. */
(0 < < 11) ? /* STTTO: Start Time-out: 0 = Noeffect. */
(0 < < 12);
这是在嵌入式中非常通用常见的赋值方式,用的是C特有的“移位”操作,每一个移位其实就是将该位置1(1<
第一步 US_CR = 0x000C;/*0b0000_0000_0000_1100 第2位,第3位为1,其他为0*/
第二步 US_CR = 0x0150; /*0b0000_0001_0101_0000 第4、6、8是1,其他是0*/
最终结果,如果不考虑硬件对其中状态位的改动,结果就是0x0150.