main.c

来自「博创2410的实验代码」· C语言 代码 · 共 81 行

C
81
字号
#include "../inc/drivers.h"
#include "../inc/lib.h"
#include <string.h>
#include <stdio.h>
#include "inc/max504.h"
#include "inc/MotorCtrl.h"
#include "inc/EXIO.h"
#pragma import(__use_no_semihosting_swi)  // ensure no functions that use semihosting 

#define MCLK (50700000)
#define MOTOR_SEVER_FRE		1000		//20kHz
#define MOTOR_CONT				(MCLK/2/2/MOTOR_SEVER_FRE)
#define MOTOR_MID				(MOTOR_CONT/2)
#define ADCCON_FLAG		(0x1<<15)
#define ADCCON_ENABLE_START_BYREAD	(0x1<<1)
#define rADCCON		(*(volatile unsigned *)0x58000000)
#define rADCDAT0	(*(volatile unsigned *)0x5800000C)
#define PRSCVL (49<<6)
#define ADCCON_ENABLE_START (0x1)
#define STDBM (0x0<<2)
#define PRSCEN (0x1<<14)
#define rADCCON  (*(volatile unsigned *)0x58000000)
#define rADCDAT0  (*(volatile unsigned *)0x5800000C)
#define rUTRSTAT0  (*(volatile unsigned *)0x50000010)
#define RdURXH0()	(*(volatile unsigned char *)0x50000024)

int main(void)
{
	int i,j,ADData,lastADData,count=0;
	char Revdata[10];
	//////////////A,		AB,	B,	BC,	C	CD,		D,	DA
	int stepdata[]={0x10,0x30,0x20,0x60,0x40,0xc0,0x80,0x90};
	
	ARMTargetInit();	//开发板初始化
	init_MotorPort();   //motor相关端口初始化 
    //add code here1
	for(;;)
	{
	begin:
		Uart_Printf(0,"\nBegin control DC motor.\t\tPress any key to control step motor.\n");
		for(;;)
		{   //add code here2
			SetPWM(MOTOR_MID);      //脉冲宽度设置    
			//hudelay(10);
			if((rUTRSTAT0 & 0x1))	//有输入,则跳出
			{
				*Revdata=RdURXH0();//读取串口输入数据
				goto next;
			}
		}

	next:
		SetPWM(0);
		Uart_Printf(0,"\nBegin control step motor.\tPress any key to control DC motor.\n");
		//hudelay(10);
		//add code here3
		for(;;)
		{
		
			if((rUTRSTAT0 & 0x1))	//有输入,则返回
			{
				*Revdata=RdURXH0();//读取串口输入数据
				goto begin;
			}
			else
			{
					for(i=7;i>=0;i--)
					{
						SETEXIOBITMASK(stepdata[i], 0xf0);//脉冲信号控制
						//hudelay(20);
					}
			}
		}
	}
	return 0;
}

	
	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?