gpioa的crl和crh是什么东西
时间: 2024-05-18 21:18:06 浏览: 24
GPIOA的CRL和CRH是GPIO端口配置寄存器(Control Register Low和Control Register High)的缩写。它们用于配置GPIO端口的引脚功能和属性。
GPIO端口具有多个引脚,每个引脚都可以配置为不同的功能模式,例如输入、输出、复用功能等。CRL和CRH寄存器用于对GPIO端口的引脚进行逐位配置。
CRL寄存器用于配置GPIO的低8位引脚(即GPIO0到GPIO7),而CRH寄存器用于配置GPIO的高8位引脚(即GPIO8到GPIO15)。每个引脚在寄存器中占据4位,用于指定引脚的模式、类型、速度和推挽等属性。
通过对CRL和CRH寄存器的设置,可以灵活地配置GPIO端口的各个引脚,以满足特定的应用需求。
相关问题
要使用STM32F103C8T6寄存器点灯,需要进行以下步骤: 1. 配置GPIO引脚为输出模式。可以通过设置GPIOx_CRL或GPIOx_CRH寄存器来实现,其中x为GPIO端口号,CRL和CRH分别对应低8位和高8位的控制寄存器。 2. 设置输出引脚的电平。可以通过设置GPIOx_BSRR或GPIOx_BRR寄存器来实现,其中BSRR用于设置引脚为高电平,BRR用于设置引脚为低电平。 例如,如果要点亮PA5引脚,可以按照以下步骤进行配置: 1. 将PA5引脚配置为输出模式,可以通过设置GPIOA_CRL寄存器的第20-23位来实现,具体代码如下: GPIOA->CRL &= ~(xF << 20); //清零第20-23位 GPIOA->CRL |= (x3 << 20); //将第20-21位设置为b0011,表示输出模式 2. 将PA5引脚设置为高电平,可以通过设置GPIOA_BSRR寄存器的第5位来实现,具体代码如下: GPIOA->BSRR = (1 << 5); //将第5位设置为1,表示输出高电平 这样就可以点亮PA5引脚了。如果要熄灭引脚,可以将GPIOA_BSRR寄存器的第21位设置为1,具体代码如下: GPIOA->BSRR = (1 << 21); //将第21位设置为1,表示输出低电平
非常好,你对使用STM32F103C8T6寄存器点灯的步骤已经有了清晰的认识。需要注意的是,在配置GPIO引脚为输出模式之前,还需要先使能GPIO外设时钟,否则无法访问GPIO寄存器。具体的代码如下:
```
// 使能GPIOA外设时钟
RCC->APB2ENR |= (1 << 2);
// 将PA5引脚配置为输出模式
GPIOA->CRL &= ~(0xF << 20); // 清零第20-23位
GPIOA->CRL |= (0x3 << 20); // 将第20-21位设置为b0011,表示输出模式
// 将PA5引脚设置为高电平
GPIOA->BSRR = (1 << 5); // 将第5位设置为1,表示输出高电平
// 将PA5引脚设置为低电平
GPIOA->BSRR = (1 << 21); // 将第21位设置为1,表示输出低电平
```
这样就可以通过STM32F103C8T6寄存器来点亮或熄灭GPIO引脚了。
void OscDispAutoMagic(unsigned char Data,u32 SizeX,u32 SizeY,u32 OffsetX,u32 OffsetY) { static u32 pos=0; static s32 x=0,y=0,z=0; static u32 id=0; #ifdef PWMlightMode if(id==0) { PAout(7)=0; #endif DAC->DHR12RD=MapData[LDcnt]; LDcnt++; if(LDcnt>=LDlen) { LDcnt=0; PAout(6)=0; } else PAout(6)=1; #ifdef PWMlightMode } else PAout(7)=1; id=(id+1)%2; #endif } u8 DispPoi=0; void TIM3_IRQHandler(void)//当 TIM3 定时器发生中断时,它会清除中断标志位,并以特定参数调用 OscDispAutoMagic 函数。 { if(TIM3->SR) { TIM3->SR=0; OscDispAutoMagic((u8)0,64,64,0,0); } } extern int Msg_PathFin; #define DPMax2 (MaxDots*2) extern u8 DotPath[DPMax2]; int main(void) { int i=0; //float x,y; Stm32_Clock_Init(9); //系统时钟设置 uart_init(72,115200); //串口初始化为115200 delay_init(72);//延时初始化 Timer3_Init(); Timer2_Init(); DAC_Init(); GPIOA->CRL&=0x00FFFFFF; GPIOA->CRL|=0x33000000; PAout(6)=0; PAout(7)=1; GPIOA->CRH&=0x00FFFFF0; GPIOA->CRH|=0x88000003; PAout(8)=1; MapData[0]=XYc_OutputInv(1000,1000); MapData[1]=XYc_OutputInv(1500,1000); MapData[2]=XYc_OutputInv(2000,1000); LDlen=3; delay_ms(5000); PAout(8)=1; while(1) { if(Msg_PathFin) { LDlen=3; for(i=0;i<Msg_PathFin;i++) { MapData[i]=XYc_Output(DotPath[2*i+1]24,DotPath[2i]*24); } if(Msg_PathFin>=MaxDots)LDlen=MaxDots; else if(Msg_PathFin>=3)LDlen=Msg_PathFin; else LDlen=Msg_PathFin+2; Msg_PathFin=0; } } } 修改代码,控制振镜XY改为控制振镜X,读取数组中值,当读取到1振镜x向左偏振,读到0振镜x向右偏转
根据你的要求,我修改了代码,使其只控制振镜X,并根据读取到的数组值决定振镜X偏转方向。以下是修改后的代码:
```cpp
void OscDispAutoMagic(unsigned char Data, u32 SizeX, u32 SizeY, u32 OffsetX, u32 OffsetY) {
static u32 pos = 0;
static s32 x = 0, y = 0, z = 0;
static u32 id = 0;
#ifdef PWMlightMode
if (id == 0) {
PAout(7) = 0;
}
#endif
if (DotPath[pos] == 1) { // 如果读取到1,振镜X向左偏转
x -= 24;
} else if (DotPath[pos] == 0) { // 如果读取到0,振镜X向右偏转
x += 24;
}
DAC->DHR12RD = XYc_Output(x, y);
pos = (pos + 1) % DPMax2;
#ifdef PWMlightMode
}
else PAout(7) = 1;
id = (id + 1) % 2;
#endif
}
u8 DispPoi = 0;
void TIM3_IRQHandler(void) {
if (TIM3->SR) {
TIM3->SR = 0;
OscDispAutoMagic((u8)0, 64, 64, 0, 0);
}
}
extern int Msg_PathFin;
#define DPMax2 (MaxDots*2)
extern u8 DotPath[DPMax2];
int main(void) {
int i = 0;
Stm32_Clock_Init(9);
uart_init(72, 115200);
delay_init(72);
Timer3_Init();
Timer2_Init();
DAC_Init();
GPIOA->CRL &= 0x00FFFFFF;
GPIOA->CRL |= 0x33000000;
PAout(6) = 0;
PAout(7) = 1;
GPIOA->CRH &= 0x00FFFFF0;
GPIOA->CRH |= 0x88000003;
PAout(8) = 1;
MapData[0] = XYc_OutputInv(1000, 1000);
MapData[1] = XYc_OutputInv(1500, 1000);
MapData[2] = XYc_OutputInv(2000, 1000);
LDlen = 3;
delay_ms(5000);
PAout(8) = 1;
while (1) {
if (Msg_PathFin) {
LDlen = 3;
for (i = 0; i < Msg_PathFin; i++) {
if (DotPath[2 * i] == 1) { // 如果读取到1,振镜X向左偏转
MapData[i] = XYc_Output(DotPath[2 * i + 1] * 24, x);
} else if (DotPath[2 * i] == 0) { // 如果读取到0,振镜X向右偏转
MapData[i] = XYc_Output(DotPath[2 * i + 1] * 24, x);
}
}
if (Msg_PathFin >= MaxDots) LDlen = MaxDots;
else if (Msg_PathFin >= 3) LDlen = Msg_PathFin;
else LDlen = Msg_PathFin + 2;
Msg_PathFin = 0;
}
}
}
```
请注意,我只根据你提供的要求修改了代码中涉及振镜X控制的部分,其他部分保持不变。请在实际使用时进行适当的调整和测试。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)