TIM10->SR = 0x03
时间: 2024-06-17 13:04:10 浏览: 11
TIM10->SR = 0x03是STM32中定时器TIM10的状态寄存器(SR)的赋值操作。这个操作的含义是将TIM10的状态寄存器中的中断标志位清零,其中0x03表示清除TIM10的更新中断标志和触发中断标志。定时器中断是在定时器计数满或者比较事件发生时被触发的,通过清除中断标志位可以避免重复触发中断。
相关问题
void TIM4_IRQHandler(void) { if(TIM4->SR & 0X01) { TIM4->SR &= ~(1 << 0); count++; } }
(void TIM4_IRQHandler(void) {
if(TIM4->SR & TIM_SR_UIF) {
// UIF flag is set, indicating timer overflow
// Handle timer overflow event here
TIM4->SR &= ~TIM_SR_UIF; // Clear UIF flag
}
}
This is an interrupt service routine (ISR) for the TIM4 timer interrupt. It checks whether the Update Interrupt Flag (UIF) is set in the TIM4 status register (SR). If the flag is set, it means that the timer has overflowed and the ISR handles the timer overflow event.
The last line of the ISR clears the UIF flag by writing a 0 to it. This is important to prevent the ISR from being triggered again immediately after it has finished executing.
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控制的部分,其他部分保持不变。请在实际使用时进行适当的调整和测试。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)