motor.c

来自「第三届飞思卡尔智能车竞赛华东赛一等奖的程序」· C语言 代码 · 共 46 行

C
46
字号
#include "motor.h"
int fault;
void Init_Motor()
{
//PJ0:电机出错监控

	PIFJ|=0x01;	//PJ0中断标志清零(电机出错标志)
	PPSJ&=~0x01;//下降沿触发
//PIEJ|=0x01;	//PJ0中断使能

//PA4:enable motor

  DDRA  |=0x10; //PA4作为输出口
  PORTA &=~0x10;//PA4=0,开电机
  	
//PWM3:Connected By PWM2&PWM3

	PWME    &=~0x0C; 	 // 关PWM3
	PWMCLK  |=0x0C;   	// 选CLOCK SB
	PWMPOL  |=0x0C; 	// Output is high at the beginning of the period,
	PWMCAE  &=~0x0C; 	// 左对齐
	
	PWMDTY23=speed_ref;  //给出PWM脉宽初始值
  PWMPER23 =1000;   // 设定周期为1000,可得到2M/1000=2KHz的脉冲
  
  PWME    |=0x0C;   // Start
  fault=0;
}

void disable_motor(void)
{
	PORTA|=0x10; //PA4=1,关电机
}

void enable_motor(void)
{
  PORTA &=~0x10;//PA4=0,开电机
}

interrupt void PJ_ISR(void)
{
//disable_motor();
	PORTB=0XE7;
	PIFJ|=0x01;
	
}

⌨️ 快捷键说明

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