📄 main.c
字号:
#include<Waking_machine.h>
#include<math.h>
extern void initial(void);
extern FuncRotate(bit BClockWise,uint step,int *PRegAngle);
extern void send(uchar *temp,uint j);
extern void delay(uint k);
uint delaycount = 20;
char XPulse=0, YPulse =0; //记录上一个100ms中X.Y方向的脉冲值
char XPulseTemp=0,YPulseTemp=0; //累加计数脉冲值
uchar rcvdata=0;
uchar debugtime=0;
uchar workmode=2;
bit EvRcv=FAULT; //接收中断(串口)标志位
bit EvTimer=FAULT; //定时时间满标志位
void main(void)
{
int RegAngle=0,RegNewAngle=0,temp=0;
int Xtmp=0,Ytmp=0;
int *Angle;
Angle=&RegAngle;
initial(); //初始化
CP=VALID; //步进脉冲信号输出有效,低电平有效
LampNormally=FAULT; //工作状态正常指示灯
PinRotIndicator=FAULT; //为1转动操作正在进行 ,转动指示灯
LampDebug=FAULT; //调试控制指示灯
LampError=FAULT; //致命错误指示灯
LampFlood=FAULT; //溢出指示灯
LampComm=FAULT; //通信指示灯
OPTO=VALID; //总控制端
OutFree=VALID; //脱机电平信号输出端
delay(2);
while(1)
{
while(InFree==VALID)
{
TR0=0; //关定时器0
OutFree=INVALID;
while(ClockWiseRot==VALID) //按钮控制顺时针转动
{
OutFree=VALID;
FuncRotate(ConstClockWise,1,Angle);
delay(500);
}
while(AntiClockRot==VALID)
{
OutFree=VALID;
FuncRotate(ConstAntiClock,1,Angle);
delay(500);
}
TR0=1;
EvTimer=FAULT;
}
OutFree=VALID;
if(EvRcv)
{
delaycount=rcvdata&0x1f;
workmode=(rcvdata&0xe0)/32;
EvRcv=FAULT;
}
if(EvTimer)
{
++debugtime;
if(debugtime==5)
{
LampNormally=TRUE;
}
else if(debugtime==10)
{
LampNormally=FAULT;
debugtime=0;
}
RegNewAngle=XPulse*XPulse+ YPulse*YPulse ;
RegNewAngle=(uint)sqrt((float)RegNewAngle);
temp=RegNewAngle-RegAngle;
if( temp>HALFMAXSTEPS)
{
temp=temp-HALFMAXSTEPS;
}
else if(temp<-HALFMAXSTEPS)
{
temp=temp+HALFMAXSTEPS;
}
if(temp>0)
{
FuncRotate(ConstAntiClock,temp,Angle);
}
if(temp<0)
{
FuncRotate(ConstAntiClock,-temp,Angle);
}
if(workmode==1)
{
send((uchar*)&RegAngle,2);
}
else if (workmode==2)
{
send((uchar*)&RegAngle,2);
send((uchar*)&XPulse,4);
send((uchar*)&YPulse,4);
}
EvTimer=FAULT;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -