⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 motor.c

📁 第三届飞思卡尔智能车竞赛华东赛一等奖的程序
💻 C
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -