在 while ((uart[2] & (1<<6)) == 0);
行下面的代码中检查硬件寄存器中是否已设置某个位。
我的问题是 - 代码创建了一个指针 *uart
它指向地址0x00021000。如果你想&
在 (1<<6) 中,您是否不必取消引用指针?
#define UART_BASE 0x00021000
void putstring(char *str) {
volatile uint32_t *uart = (volatile uint32_t*) UART_BASE;
while (1)
{
while (*str != '\0')
{
while ((uart[2] & (1<<6)) == 0);
uart[1] = *str;
str++;
}
}
}
最佳答案
在 C 语言中,x[y]
相当于 *(x+y)
。因此,当您执行uart[2]
时,您正在取消引用指针。
关于c - 您不需要取消引用指针来对寄存器进行按位操作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42694525/