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

📄 wushua.h

📁 电动车程序和原理图,该程序和原理已经批量生产,由于不同的电机会有差异,使用时要重新进行一些参数的调整,该程序也可作为一般直流无刷电机驱动程序,具有低成本高性能的特点
💻 H
字号:
//**************************************************************************
//                  无有刷电机控制程序头文件
//    BY:            Sunny.xu
//    Data:          2004.06.19
//    Version        V1.0
//
//**************************************************************************


//********************************//
//                                //
//      常量定义区 				  //
//                                //
//********************************//

const unsigned char AD_CHNNEL0=0x81;
const unsigned char AD_CHNNEL1=0x89;
const unsigned char AD_CHNNEL2=0x91;
const unsigned char AD_CHNNEL3=0x99;
const unsigned char AD_CHNNEL4=0xA1;
const unsigned char AD_CHNNEL5=0xA9;

const unsigned char PWR_0_LOW =160;
const unsigned char PWR_0_HIGH=162;//162;
const unsigned char PWR_1_LOW =170;//169;
const unsigned char PWR_1_HIGH=170;//171;
const unsigned char PWR_2_LOW =179;//178;
const unsigned char PWR_2_HIGH=179;//180;
const unsigned char PWR_3_LOW =187;//186;
const unsigned char PWR_3_HIGH=187;//188;

const unsigned char START_RUN=80;			//马达开始转动
const unsigned char OVER_LOAD=100;			//飞车监测上限
const unsigned char KEY_INITIAL=0x10;		//按键初始化
const unsigned char ALARM_HIGH=30;		//报警响
const unsigned char ALARM_LOW=40;		//报警不响
const unsigned char DS_TIME=100;		//进入定速的时间
const unsigned char DS_MODE_TIME=10;		//进入定速的时间
const unsigned char PHASE_DATA[7]={0x0B,0x2A,0x89,0x29,0x43,0x4A,0x83};




//********************************//
//                                //
//      硬件接口位变量定义区    	  //
//                                //
//********************************//
//********************************//
/*      PORTA bits      */
static volatile bit	KEY_MODE	@ (unsigned)&PORTA*8+5;		//模式按钮 0: 按下
//static volatile bit	RA4	@ (unsigned)&PORTA*8+4;
//static volatile bit	RA3	@ (unsigned)&PORTA*8+3;   
//static volatile bit	RA2	@ (unsigned)&PORTA*8+2;    
static volatile bit	SPEED_DTC	@ (unsigned)&PORTA*8+1;    
static volatile bit	BATT_DTC	@ (unsigned)&PORTA*8+0;    //电池电压监测 3.15V//3.33V//3.5V//3.65V

/*      PORTB bits      */
static volatile bit	BREAK_IN	@ (unsigned)&PORTB*8+7;		//刹车信号输入端 1:刹车
static volatile bit	PHASE_C_IN	@ (unsigned)&PORTB*8+6;    
static volatile bit	PHASE_B_IN	@ (unsigned)&PORTB*8+5;    
static volatile bit	PHASE_A_IN	@ (unsigned)&PORTB*8+4;    
static volatile bit	ZHULI_DTC	@ (unsigned)&PORTB*8+3;    //助力信号监测输入端
static volatile bit	S_DATA  	@ (unsigned)&PORTB*8+2;    //164 DTAT
static volatile bit	S_CLK     	@ (unsigned)&PORTB*8+1;    //164 CLK
static volatile bit	CURRENT		@ (unsigned)&PORTB*8+0;    //电流监测输入端 0:过流状态

/*      PORTC bits      */
static volatile bit	PHASE_B_H	@ (unsigned)&PORTC*8+7;		
static volatile bit	PHASE_C_H	@ (unsigned)&PORTC*8+6;    
static volatile bit	PHASE_A_H	@ (unsigned)&PORTC*8+5;    
static volatile bit	UP_SPEED	@ (unsigned)&PORTC*8+4;    //极限速度       0:80% 1: 100%
static volatile bit	PHASE_A_L  	@ (unsigned)&PORTC*8+3;    
static volatile bit	MOTOR_CON	@ (unsigned)&PORTC*8+2;    //电机控制
static volatile bit	PHASE_C_L     	@ (unsigned)&PORTC*8+1;    
static volatile bit	PHASE_B_L		@ (unsigned)&PORTC*8+0;    

//********************************//
//                                //
//      变量定义区			      //
//                                //
//********************************//
unsigned char Key_Temp0 @ 0x2C;

unsigned char i	@	0x2D;

volatile unsigned	int		Main_Flag0		@	0x2E;
static  	bit		WORK_STA 	@ (unsigned)&Main_Flag0*8+0;    	//1:已开锁标志
static  	bit		ERR_DISP_OK	@ (unsigned)&Main_Flag0*8+1;    	//1:错误显示标志
static  	bit		ALL_OFF_1ST	@ (unsigned)&Main_Flag0*8+2;    	//1:消隐

static  	bit		MODE_DOWN 	@ (unsigned)&Main_Flag0*8+5;		//1:模式按钮按下
static  	bit		PWR_ON  	@ (unsigned)&Main_Flag0*8+6;		//1:上电标志位
static  	bit		MS_5_OK 	@ (unsigned)&Main_Flag0*8+7;		//5ms ok
    
static  	bit		ALL_OFF 	@ (unsigned)&Main_Flag0*8+8;		//1:消隐
static  	bit		TIME_ZHULI_OK 	@ (unsigned)&Main_Flag0*8+9;		//1
static  	bit		PWR_LOW_STA 	@ (unsigned)&Main_Flag0*8+10;	//
static  	bit		CUR_OVER 		@ (unsigned)&Main_Flag0*8+11;
static  	bit		BREAK_ST 		@ (unsigned)&Main_Flag0*8+12;
static  	bit		TIME_OVER 	 	@ (unsigned)&Main_Flag0*8+13;
static  	bit		WITH_ERR	 	@ (unsigned)&Main_Flag0*8+14;
static  	bit		MS_1_OK 	 	@ (unsigned)&Main_Flag0*8+15;



volatile unsigned	int		Main_Flag		@	0x31;
volatile unsigned	char	Main_Flag1		@	0x31;
volatile unsigned	char	Main_Flag2		@	0x32;

static  	bit		PWR_LOW 	@ (unsigned)&Main_Flag*8+0; //1:欠压状态   
static  	bit		PWR_LED0 	@ (unsigned)&Main_Flag*8+1;    
static  	bit		PWR_LED1 	@ (unsigned)&Main_Flag*8+2;    
static  	bit		PWR_LED2 	@ (unsigned)&Main_Flag*8+3;    
static  	bit		PWR_LED3 	@ (unsigned)&Main_Flag*8+4;
static		bit  	DINGSU		@ (unsigned)&Main_Flag*8+5;	//1:定速状态
static		bit		DIANDONG	@ (unsigned)&Main_Flag*8+6;	//1:电动状态
static		bit  	ZHULI		@ (unsigned)&Main_Flag*8+7;	//1:助力状态
    
static  	bit		BREAK_EN 	@ (unsigned)&Main_Flag*8+8;		//1:刹车信号使能 0:不在刹车状态
static  	bit		CUR_LIMIT 	@ (unsigned)&Main_Flag*8+9;		//1: 限流状态 0: 正常工作状态
static  	bit		KEY_PRO_EN 	@ (unsigned)&Main_Flag*8+10;
static  	bit		KEY_ORDER 	@ (unsigned)&Main_Flag*8+11;
static  	bit		KEY_UP	 	@ (unsigned)&Main_Flag*8+12;	//按键抬起标志
static  	bit		ERR_SPEED 	@ (unsigned)&Main_Flag*8+13;	//调速出错
static  	bit		ERR_BREAK 	@ (unsigned)&Main_Flag*8+14;	//刹车出错
static  	bit		ERR_MODE 	@ (unsigned)&Main_Flag*8+15;	//模式按钮出错



unsigned	char	Power_Voltage	@	0x33;		//电源电压
unsigned	char	Speed_Voltage	@	0x34;		//速度
unsigned	char	Speed_Voltage_Old	@	0x35;	//速度
unsigned	char	Pwm_Duty		@	0x36;		//PWM			
unsigned	char	Disp_Data 	 	@	0x37;		//显示数据
static		bit		Msb_Disp_Data@ (unsigned)&Disp_Data*8+7;
unsigned	char	Key_Data0 	 	@	0x38;		//按键数据0
unsigned	char	Key_Data1 	 	@	0x39;		//按键数据1
unsigned	char	Key_Result 	 	@	0x3A;		//最终按键数据
static		bit		KEY0			@ (unsigned)&Key_Result*8;		//开锁
static		bit		KEY1			@ (unsigned)&Key_Result*8+1;	//锁车
static		bit		KEY2			@ (unsigned)&Key_Result*8+2;	//静音
static		bit		KEY3			@ (unsigned)&Key_Result*8+3;	//寻车
static		bit		KEY4			@ (unsigned)&Key_Result*8+4;	//模式
static		bit		KEY5			@ (unsigned)&Key_Result*8+5;	
static		bit		KEY6			@ (unsigned)&Key_Result*8+6;	//刹车
static		bit		KEY7			@ (unsigned)&Key_Result*8+7;	//限流
volatile unsigned	char	Time_Base	 	@	0x3B;		//100mS定时基准
volatile unsigned	char	Time_Mode	 	@	0x3C;		//模式按钮定时
volatile unsigned	char	Time_Err_Speed 	@	0x3D;		//模式按钮定时
volatile unsigned	char	Time_Speed 	@	0x3E;		//模式按钮定时
volatile unsigned	char	Time_Zhuli 	@	0x3F;		//
unsigned	char	Zhuli_Count 		@	0x40;		//
unsigned	char	Zhuli_Duty  		@	0x41;		//
unsigned	char	AD_Turn  			@	0x42;		//
unsigned	char	Disp_Data_Old  		@	0x43;		//
unsigned	char	Zhuli_Low	 		@	0x44;		//
unsigned	char	Zhuli_High	 		@	0x45;		//
unsigned	char	Pwr_Low_Count 		@	0x46;		//
unsigned	char	Pwm_Low 			@	0x47;		//
unsigned	char	Pwm_High 			@	0x48;		//
unsigned	char	Pwm_Old 			@	0x49;		//
unsigned	char	Time_All_Err		@	0x4A;		//
unsigned	char	Pwr_Low_Num 		@	0x4B;		//
unsigned	char	Pwr_Up_Num 			@	0x4C;		//
unsigned	char	Phase_Dtc 			@	0x4E;		//
unsigned	char	Phase_Dtc_Old		@	0x4F;		//
unsigned	char	Phase_Dtc_Led		@	0x50;		//
unsigned	char	Time_Motor_Ph		@	0x51;		//
unsigned	char	Phase_Ch_Count		@	0x52;
unsigned	char	Phase_Ch_Count1		@	0x53;
unsigned	char	Cur_Over_Time		@	0x54;
unsigned	char	Cur_Over_Count		@	0x55;
unsigned	char	Time_Break			@	0x56;		//
unsigned	char	DS_Pwm_Duty			@	0x57;		//
unsigned	char	Zhuli_Count1		@	0x58;		//
unsigned	char	Zhuli_Count2		@	0x59;		//
unsigned	char	Zhuli_Low_Bak		@	0x5A;		//
unsigned	char	Zhuli_High_Bak		@	0x5B;		//
unsigned	char	Current_High		@	0x5C;		//
unsigned	char	Old_ZL_Duty			@	0x5D;		//

⌨️ 快捷键说明

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