📄 main.c
字号:
#include"uhal.h"
#include "44b.h"
#include"myuart.h"
#include"motorctrl.h"
#include"exio.h"
#include "option.h"
#include <math.h>
#pragma import(__use_no_semihosting_swi) // ensure no functions that use semihosting
#define MOTOR_SEVER_FRE 1000 //20kHz
#define MOTOR_CONT (MCLK/2/2/MOTOR_SEVER_FRE)
#define MOTOR_MID (MOTOR_CONT/2)
#define ADCCON_FLAG 0x40
#define ADCCON_SLEEP 0x20
#define ADCCON_ADIN0 (0x0<<2)
#define ADCCON_ADIN1 (0x1<<2)
#define ADCCON_ADIN2 (0x2<<2)
#define ADCCON_ADIN3 (0x3<<2)
#define ADCCON_ADIN4 (0x4<<2)
#define ADCCON_ADIN5 (0x5<<2)
#define ADCCON_ADIN6 (0x6<<2)
#define ADCCON_ADIN7 (0x7<<2)
#define ADCCON_READ_START 0x2
#define ADCCON_ENABLE_START 0x1
void init_ADdevice()
{
rADCPSR=20;
rADCCON=ADCCON_SLEEP;
}
int GetADresult(int channel)
{
rADCCON=(channel<<2)|ADCCON_ENABLE_START;
Delay(10);
while(!(rADCCON&ADCCON_FLAG));
return rADCDAT;
}
char ReadIO()
{
char temp=0;
temp = (rPDATE&0x40)|(rPDATF&0x18);
return(temp);
}
int main(void)
{
int i;
char data;
// char Revdata[10];
////////////// A, AB, B, BC, C CD, D, DA
int stepdata[]={0x10,0x30,0x20,0x60,0x40,0xc0,0x80,0x90};
ARMTargetInit(); //开发版初始化
init_MotorPort();
init_ADdevice();
for(;;)
{
data = ReadIO();
if(data==0x8)
for(i=((sizeof(stepdata)/sizeof(int))-1);i>=0;i--) //电机正转
{
SETEXIOBITMASK(stepdata[i], 0xf0);
Delay(200);
}
else if(data==0x10)
for(i=0;i<sizeof(stepdata)/sizeof(int);i++) //电机反转
{
SETEXIOBITMASK(stepdata[i], 0xf0);
Delay(200);
}
else Delay(200); //电机停止
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -