📄 main.c
字号:
/////////////////////////////////////////////////////////////////
#include "config.h"
#include "USBConfig.h" /* 加入USB相关头文件 */
#include "USBCI.h"
#include "USBDriver.h"
/////////////////////////////////////////////////////////////////
#define UART1_bps 9600 //串口通信波特率
typedef struct UartMode //定义串口模式设置数据结构
{
uint8 datab; //字长度,5、6、7、8可选
uint8 parity; //奇偶校验位,0:无校验、1:奇校验、2:偶校验
uint8 stopb; //停止位,1、2可选
}UARTMODE;
uint8 PumpIni1[10] = {0x2F,0x31,0x5A,0x35,0x53,0x32,0x30,0x52,0x0D,'\0'}; //初始化
uint8 PumpIniQ[10] = {'/','1','Z','5','S','2','0','R',0x0D,'\0'}; //初始化
uint8 PumpIniS[10] = {'/','1','Z','5','S','8','0','R',0x0D,'\0'}; //初始化
uint8 PumpIni[11] = {'/','1','Z','5','S','0','0','0','R',0x0D,'\0'}; //初始化
uint8 PumpAir[9] = {'/','1','O','A','4','0','R',0x0D,'\0'}; //吸25ul空气
uint8 PumpAirL[9] = {'/','1','O','A','2','0','R',0x0D,'\0'}; //吸25ul空气
uint8 PumpGet[10] = {'/','1','O','A','0','0','0','R',0x0D,'\0'}; //取样
uint8 SendToPump[10] = {0x2F,0x31,0x5A,0x35,0x53,0x32,0x30,0x52,0x0D,'\0'};
uint8 PumpCln[13] = {'/','1','I','A','8','0','0','O','A','0','R',0x0D,'\0'};
int SampleOverFlag = 0;
/////////////////////////////////////////////////////////////////
const uint32 M = (0xF << 3) | (0xF << 16) | (0xF << 10) | (0x1 << 20) | (0x1 << 21); //P0[23:20]控制M1
const uint32 MD = 0x3FF << 16; //P0[19:16]控制M2
const uint32 M2P = 0x1 << 16; //P1.16接收M2的定位光耦信号,5号光耦-上下电机
const uint32 M2D = 0x1 << 17; //P1.17接收M2的方向光耦信号,6号光耦-上下电机
const uint32 M3P = 0x1 << 21; //P1.18接收M3的定位光耦信号,3号光耦-左右电机
const uint32 M3D = 0x1 << 18; //P1.19接收M3的方向光耦信号,4号光耦-左右电机
const uint32 M4P = 0x1 << 19; //P1.20接收M4的定位光耦信号,1号光耦-盘电机
const uint32 M4D = 0x1 << 20; //P1.21接收M4的方向光耦信号,2号光耦-盘电机
const uint32 K2 = 0x1 << 24; //向上按钮
const uint32 K1 = 0x1 << 25; //向下按钮
//int q1 = 0;
int q2 = 0;
int q3 = 0;
int q4 = 0;
int Direction = 0; //0:顺时针、1:逆时针
int MotorSelected; //选择的电机号
int M2PF;
int M2DF;
int GFinFlag = 0;
int GFinStep = 0;
int GFRStep = 0;
unsigned char GFinStepF[10] = {'g','f','i','n','0','0','0','#','#','#'};
int CLinFlag = 0;
int CLinStep = 0;
int CLRStep = 0;
unsigned char CLinStepF[10] = {'c','l','i','n','0','0','0','#','#','#'};
int SDinFlag = 0;
int SDinStep = 0;
int SDRStep = 0;
unsigned char SDinStepF[10] = {'s','d','i','n','0','0','0','#','#','#'};
int K1Flag = 0;
int K2Flag = 0;
int CDiskStep = 8;//60; //盘初始化判到下面的光耦后多逆转的步数
int SetCLStep = 0;
int SetSDStep = 0;
int SetGFStep = 0;
int SetFlag = 0;
int DiskNumNow = 0;
int DiskNumNext = 0;
int Add1Flag = 0;
int Add2Flag = 0;
int Add3Flag = 0;
int Add1Sample = 0;
int Add2Sample = 0;
int Add3Sample = 0;
int Add1Number = 0;
int Add2Number = 0;
int Add3Number = 0;
int CleanNumber = 0;
int CleanFlag = 0;
int DiskNum01 = 360;
int DiskNum21 = 460;
int DiskNum41 = 590;
int OlnyCleanNum = 0;
int CleanHole = 100;
/////////////////////////////////////////////////////////////////
//const uint32 EINT1 = 0x2 << 28; //P0.14设为外部中断脚EINT1
/////////////////////////////////////////////////////////////////
unsigned char SendToUsb[2];
unsigned char ReceiveOK[10] = {'r','e','c','e','i','v','e','o','k','#'};
unsigned char SetOK[10] = {'s','e','t','o','k','#','#','#','#','#'};
unsigned char NoSet[10] = {'n','o','s','e','t','#','#','#','#','#'};
unsigned char DiskOK[10] = {'d','i','s','k','o','k','#','#','#','#'};
unsigned char ControlOK[10] = {'c','o','n','t','r','o','l','o','k','#'};
unsigned char DiskError[10] = {'d','i','s','k','e','r','r','o','r','#'};
unsigned char Continue[10] = {'x','c','o','n','t','i','n','u','e','#'};
unsigned char Delay[10] = {'d','e','l','a','y','#','#','#','#','#'};
unsigned char USBOK[10] = {'u','s','b','o','k','#','#','#','#','#'};
unsigned char ControlOK1[10] = {'c','o','n','t','r','o','l','o','k','1'};
unsigned char ControlOK2[10] = {'c','o','n','t','r','o','l','o','k','2'};
unsigned char ControlOK3[10] = {'c','o','n','t','r','o','l','o','k','3'};
unsigned char ControlOK4[10] = {'c','o','n','t','r','o','l','o','k','4'};
unsigned char ControlOK5[10] = {'c','o','n','t','r','o','l','o','k','5'};
unsigned char ControlOK6[10] = {'c','o','n','t','r','o','l','o','k','6'};
unsigned char ControlOK7[10] = {'c','o','n','t','r','o','l','o','k','7'};
unsigned char ControlOK8[10] = {'c','o','n','t','r','o','l','o','k','8'};
unsigned char ControlOK9[10] = {'c','o','n','t','r','o','l','o','k','9'};
unsigned char ControlOK10[10] = {'c','o','n','t','r','o','l','o','1','0'};
unsigned char ControlOK11[10] = {'c','o','n','t','r','o','l','o','1','1'};
unsigned char ControlOK12[10] = {'c','o','n','t','r','o','l','o','1','2'};
unsigned char ControlOK13[10] = {'c','o','n','t','r','o','l','o','1','3'};
unsigned char ControlOK14[10] = {'c','o','n','t','r','o','l','o','1','4'};
unsigned char ControlOK15[10] = {'c','o','n','t','r','o','l','o','1','5'};
unsigned char ControlOK16[10] = {'c','o','n','t','r','o','l','o','1','6'};
unsigned char ControlOK17[10] = {'c','o','n','t','r','o','l','o','1','7'};
unsigned char ControlOK18[10] = {'c','o','n','t','r','o','l','o','1','8'};
unsigned char ControlOK19[10] = {'c','o','n','t','r','o','l','o','1','9'};
unsigned char ControlOK20[10] = {'c','o','n','t','r','o','l','o','2','0'};
/////////////////////////////////////////////////////////////////
void Init_USBInterrupt(void)
{
VICVectCntl0 = (0x20 | 22); /* USB中断分配到中断向量0 */
VICVectAddr0 = (INT32U)Usb_Exception; /* USB中断服务程序地址 */
VICIntEnable = 1 << 22; /* 使能USB中断 */
}
/////////////////////////////////////////////////////////////////
void UART1_ini()
{
uint16 Fdiv;
UARTMODE set;
PINSEL0 = (PINSEL0 & (~(0x0F << 16))) | (0x05 << 16); //P0.8 P0.9选择UART1功能
U1LCR = 0x83;
Fdiv = (Fpclk / 16)/UART1_bps;
U1DLM = Fdiv / 256;
U1DLL = Fdiv % 256;
U1LCR = 0x03;
set.datab = 8; //字长度,5、6、7、8可选
set.parity = 0; //奇偶校验位,0:无校验、1:奇校验、2:偶校验
set.stopb = 1; //停止位,1、2可选
}
void UART1_SendByte(uint8 dat)
{
U1THR = dat;
while ((U1LSR & 0x40) == 0); // 等待数据发送完毕
}
void UART1_SendStr(uint8 const *str)
{
while (1)
{
if (*str == '\0')
{
break; // 遇到结束符,退出
}
UART1_SendByte(*str++); // 发送数据
}
}
/////////////////////////////////////////////////////////////////
/*void SMC1_out()
{
q1 = q1%8;
if(Direction == 0 ) //顺时针
{
if( q1 == 0 )
{
IO0PIN = 0xE << 20;
}
else if( q1 == 1)
{
IO0PIN = 0xC << 20;
}
else if( q1 == 2)
{
IO0PIN = 0xD << 20;
}
else if( q1 == 3)
{
IO0PIN = 0x9 << 20;
}
else if( q1 == 4)
{
IO0PIN = 0xB << 20;
}
else if( q1 == 5)
{
IO0PIN = 0x3 << 20;
}
else if( q1 == 6)
{
IO0PIN = 0x7 << 20;
}
else if( q1 == 7)
{
IO0PIN = 0x6 << 20;
}
}
else if(Direction == 1) //逆时针
{
if(q1 == 0 )
{
IO0PIN = 0x6 << 20;
}
else if( q1 == 1)
{
IO0PIN = 0x7 << 20;
}
else if( q1 == 2)
{
IO0PIN = 0x3 << 20;
}
else if( q1 == 3)
{
IO0PIN = 0xB << 20;
}
else if( q1 == 4 )
{
IO0PIN = 0x9 << 20;
}
else if( q1 == 5)
{
IO0PIN = 0xD << 20;
}
else if( q1 == 6)
{
IO0PIN = 0xC << 20;
}
else if( q1 == 7)
{
IO0PIN = 0xE << 20;
}
}
q1++;
}*/
void SMC2_out()
{
q2 = q2%8;
if(Direction == 0 ) //顺时针
{
if( q2 == 0 )
{
IO0PIN = 0xE << 16;
}
else if( q2 == 1)
{
IO0PIN = 0xC << 16;
}
else if( q2 == 2)
{
IO0PIN = 0xD << 16;
}
else if( q2 == 3)
{
IO0PIN = 0x9 << 16;
}
else if( q2 == 4)
{
IO0PIN = 0xB << 16;
}
else if( q2 == 5)
{
IO0PIN = 0x3 << 16;
}
else if( q2 == 6)
{
IO0PIN = 0x7 << 16;
}
else if( q2 == 7)
{
IO0PIN = 0x6 << 16;
}
}
else if(Direction == 1) //逆时针
{
if(q2 == 0 )
{
IO0PIN = 0x6 << 16;
}
else if( q2 == 1)
{
IO0PIN = 0x7 << 16;
}
else if( q2 == 2)
{
IO0PIN = 0x3 << 16;
}
else if( q2 == 3)
{
IO0PIN = 0xB << 16;
}
else if( q2 == 4 )
{
IO0PIN = 0x9 << 16;
}
else if( q2 == 5)
{
IO0PIN = 0xD << 16;
}
else if( q2 == 6)
{
IO0PIN = 0xC << 16;
}
else if( q2 == 7)
{
IO0PIN = 0xE << 16;
}
}
q2++;
}
void SMC2_out1()
{
q2 = q2%8;
if(Direction == 0) //顺时针
{
;
}
else if(Direction == 1) //逆时针
{
q2 = q2+6;
}
q2 = q2%8;
if( q2 == 0 )
{
IO0PIN = 0xE << 16;
}
else if( q2 == 1)
{
IO0PIN = 0xC << 16;
}
else if( q2 == 2)
{
IO0PIN = 0xD << 16;
}
else if( q2 == 3)
{
IO0PIN = 0x9 << 16;
}
else if( q2 == 4)
{
IO0PIN = 0xB << 16;
}
else if( q2 == 5)
{
IO0PIN = 0x3 << 16;
}
else if( q2 == 6)
{
IO0PIN = 0x7 << 16;
}
else if( q2 == 7)
{
IO0PIN = 0x6 << 16;
}
q2++;
}
void SMC3_out()
{
q3 = q3%8;
if(Direction == 0 ) //顺时针
{
if( q3 == 0 )
{
IO0PIN = (0xE << 10) | (0x1 << 21);
}
else if( q3 == 1)
{
IO0PIN = (0xC << 10) | (0x0 << 21);
}
else if( q3 == 2)
{
IO0PIN = (0xD << 10) | (0x0 << 21);
}
else if( q3 == 3)
{
IO0PIN = (0x9 << 10) | (0x0 << 21);
}
else if( q3 == 4)
{
IO0PIN = (0xB << 10) | (0x1 << 21);
}
else if( q3 == 5)
{
IO0PIN = (0x3 << 10) | (0x1 << 21);
}
else if( q3 == 6)
{
IO0PIN = (0x7 << 10) | (0x1 << 21);
}
else if( q3 == 7)
{
IO0PIN = (0x6 << 10) | (0x1 << 21);
}
}
else if(Direction == 1) //逆时针
{
if(q3 == 0 )
{
IO0PIN = (0x6 << 10) | (0x1 << 21);
}
else if( q3 == 1)
{
IO0PIN = (0x7 << 10) | (0x1 << 21);
}
else if( q3 == 2)
{
IO0PIN = (0x3 << 10) | (0x1 << 21);
}
else if( q3 == 3)
{
IO0PIN = (0xB << 10) | (0x1 << 21);
}
else if( q3 == 4 )
{
IO0PIN = (0x9 << 10) | (0x0 << 21);
}
else if( q3 == 5)
{
IO0PIN = (0xD << 10) | (0x0 << 21);
}
else if( q3 == 6)
{
IO0PIN = (0xC << 10) | (0x0 << 21);
}
else if( q3 == 7)
{
IO0PIN = (0xE << 10) | (0x1 << 21);
}
}
q3++;
}
void SMC3_out1()
{
q3 = q3%8;
if(Direction == 0) //顺时针
{
;
}
else if(Direction == 1) //逆时针
{
q3 = q3+6;
}
q3 = q3%8;
if( q3 == 0 )
{
IO0PIN = (0xE << 10) | (0x1 << 21);
}
else if( q3 == 1)
{
IO0PIN = (0xC << 10) | (0x0 << 21);
}
else if( q3 == 2)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -