#define MaxDots 1024 u32 MapData[MaxDots]; int LDcnt=0,LDdir=1; int LDlen=MaxDots; s32 xDir=1,yDir=1; 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向右偏转、
时间: 2023-11-06 16:07:05 浏览: 76
根据你的要求,我修改了代码,使其只控制振镜X,并根据读取到的数组值决定振镜X偏转方向(1为向左偏转,0为向右偏转)。以下是修改后的代码:
```cpp
#define MaxDots 1024
u32 MapData[MaxDots];
int LDcnt = 0, LDdir = 1;
int LDlen = MaxDots;
s32 xDir = 1, yDir = 1;
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 = 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) {
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);
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控制的部分,其他部分保持不变。请在实际使用时进行适当的调整和测试。
阅读全文