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

📄 main.s

📁 一个正在应用的步进电机控制程序,包括电机的调速,正反,细分,通讯控制
💻 S
📖 第 1 页 / 共 4 页
字号:
	.module main.c
	.area eeprom(rom, con, rel)
_space_eeprom::
	.word 0
	.dbfile C:\BJQD\main.c
	.dbsym e space_eeprom _space_eeprom i
_speed_eeprom::
	.word 100
	.dbsym e speed_eeprom _speed_eeprom i
_state_eeprom::
	.byte 0
	.dbsym e state_eeprom _state_eeprom c
_pump_tab_eeprom::
	.byte 1
	.dbsym e pump_tab_eeprom _pump_tab_eeprom c
_state_other_eeprom::
	.byte 0
	.dbsym e state_other_eeprom _state_other_eeprom c
	.area code(ram, con, rel)
	.dbfile C:\BJQD\main.c
	.area lit(rom, con, rel)
_tabsin::
	.byte 0,6
	.byte 13,19
	.byte 25,31
	.byte 37,44
	.byte 50,56
	.byte 62,'D
	.byte 'J,'P
	.byte 'V,92
	.byte 'b,'g
	.byte 'm,'s
	.byte 'x,126
	.byte 131,136
	.byte 142,147
	.byte 152,157
	.byte 162,167
	.byte 171,176
	.byte 180,185
	.byte 189,193
	.byte 197,201
	.byte 205,208
	.byte 212,215
	.byte 219,222
	.byte 225,228
	.byte 231,233
	.byte 236,238
	.byte 240,242
	.byte 244,246
	.byte 247,249
	.byte 250,251
	.byte 252,253
	.byte 254,254
	.byte 255,255
	.byte 255,255
	.byte 255,254
	.byte 254,253
	.byte 252,251
	.byte 250,249
	.byte 247,246
	.byte 244,242
	.byte 240,238
	.byte 236,233
	.byte 231,228
	.byte 225,222
	.byte 219,215
	.byte 212,208
	.byte 205,201
	.byte 197,193
	.byte 189,185
	.byte 180,176
	.byte 171,167
	.byte 162,157
	.byte 152,147
	.byte 142,136
	.byte 131,126
	.byte 'x,'s
	.byte 'm,'g
	.byte 'b,92
	.byte 'V,'P
	.byte 'J,'D
	.byte 62,56
	.byte 50,44
	.byte 37,31
	.byte 25,19
	.byte 13,6
	.dbsym e tabsin _tabsin A[128:128]kc
_tabcos::
	.byte 255,255
	.byte 255,254
	.byte 254,253
	.byte 252,251
	.byte 250,249
	.byte 247,246
	.byte 244,242
	.byte 240,238
	.byte 236,233
	.byte 231,228
	.byte 225,222
	.byte 219,215
	.byte 212,208
	.byte 205,201
	.byte 197,193
	.byte 189,185
	.byte 180,176
	.byte 171,167
	.byte 162,157
	.byte 152,147
	.byte 142,136
	.byte 131,126
	.byte 'x,'s
	.byte 'm,'g
	.byte 'b,92
	.byte 'V,'P
	.byte 'J,'D
	.byte 62,56
	.byte 50,44
	.byte 37,31
	.byte 25,19
	.byte 13,6
	.byte 0,6
	.byte 13,19
	.byte 25,31
	.byte 37,44
	.byte 50,56
	.byte 62,'D
	.byte 'J,'P
	.byte 'V,92
	.byte 'b,'g
	.byte 'm,'s
	.byte 'x,126
	.byte 131,136
	.byte 142,147
	.byte 152,157
	.byte 162,167
	.byte 171,176
	.byte 180,185
	.byte 189,193
	.byte 197,201
	.byte 205,208
	.byte 212,215
	.byte 219,222
	.byte 225,228
	.byte 231,233
	.byte 236,238
	.byte 240,242
	.byte 244,246
	.byte 247,249
	.byte 250,251
	.byte 252,253
	.byte 254,254
	.byte 255,255
	.dbsym e tabcos _tabcos A[128:128]kc
	.area data(ram, con, rel)
	.dbfile C:\BJQD\main.c
	.area vector(rom, abs)
	.org 24
	jmp _time1_int
	.area data(ram, con, rel)
	.dbfile C:\BJQD\main.c
	.area vector(rom, abs)
	.org 12
	jmp _time2_int
	.area data(ram, con, rel)
	.dbfile C:\BJQD\main.c
	.area vector(rom, abs)
	.org 4
	jmp _pull_int
	.area data(ram, con, rel)
	.dbfile C:\BJQD\main.c
	.area text(rom, con, rel)
	.dbfile C:\BJQD\main.c
	.dbfunc e time1_int _time1_int fV
;              j -> R16
;              i -> R18
	.even
_time1_int::
	st -y,R2
	st -y,R3
	st -y,R16
	st -y,R18
	st -y,R24
	st -y,R25
	st -y,R30
	st -y,R31
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 130
; /*ICC-AVR application builder : 2004-3-11 12:02:11
; // Target : M16
; // Crystal: 8.0000Mhz
; 主程序
; ******************************************************************************/
; #include <iom16v.h>
; #include <macros.h>
; #include <eeprom.h>
; #include <stdlib.h>
; #include <math.h>
; #include "main.h"
; #include "eeprom_l.h"
; #include "delay.h"
; #include "comm.h"
; #include "key.h"
; 
; //eeprom 中的数据表
; #pragma data:eeprom
; /*
; {0x0000(2),speed_romaddr(2),state_romaddr(1),pump_tab_romaddr(1),
; state_other_romaddr(1)}
; */
; unsigned int space_eeprom=0000;
; unsigned int speed_eeprom=100;
; unsigned char state_eeprom=0;
; unsigned char pump_tab_eeprom=1;
; unsigned char state_other_eeprom=0;
;     							
; #pragma data:code
; const unsigned char tabsin[]={
; 0,6,13,19,25,31,37,44,50,56,62,68,74,80,86,92,
; 98,103,109,115,120,126,131,136,142,147,152,157,162,167,171,176,
; 180,185,189,193,197,201,205,208,212,215,219,222,225,228,231,233,
; 236,238,240,242,244,246,247,249,250,251,252,253,254,254,255,255,
; 255,255,255,254,254,253,252,251,250,249,247,246,244,242,240,238,
; 236,233,231,228,225,222,219,215,212,208,205,201,197,193,189,185,
; 180,176,171,167,162,157,152,147,142,136,131,126,120,115,109,103,
; 98,92,86,80,74,68,62,56,50,44,37,31,25,19,13,6,
; };
; const unsigned char tabcos[]={  
; 255,255,255,254,254,253,252,251,250,249,247,246,244,242,240,238,
; 236,233,231,228,225,222,219,215,212,208,205,201,197,193,189,185,
; 180,176,171,167,162,157,152,147,142,136,131,126,120,115,109,103,
; 98,92,86,80,74,68,62,56,50,44,37,31,25,19,13,6,
; 0,6,13,19,25,31,37,44,50,56,62,68,74,80,86,92,
; 98,103,109,115,120,126,131,136,142,147,152,157,162,167,171,176,
; 180,185,189,193,197,201,205,208,212,215,219,222,225,228,231,233,
; 236,238,240,242,244,246,247,249,250,251,252,253,254,254,255,255, 
; };
; 
; #pragma data:data
; 
; //全局变量
; unsigned int        speed;	  		  //16位速度寄存器
; unsigned int   		out_ctr;		  //16位AD转换值寄存器
; unsigned int        pull_number;       //闸门时间的脉冲数
; unsigned int  	    time_da;		  //16位D/A时间寄存器
; unsigned int        time_da0;
; unsigned char       key;	 		  //按键值
; unsigned char 		da_counter;		  //8位计数器:纪录正在读取的细分表位置
; unsigned char 		micros_nu;		  //8位寄存器:纪录细分数如4,8,16,32,64,128,256
; unsigned char  		micros_nu0;       //最终纪录细分数
; unsigned char       key_state;        //1:禁止      0:允许
; //key_state.0       run/stop
; //key_state.1 		cw/ccw
; //key_state.2 		max
; //key_state.3 		enter
; //key_state.4		
; unsigned char       key_counter;      //键盘加减计数器
; unsigned long       disp_time_counter0;
; unsigned long       disp_time_counter1;
; unsigned char 		add_dec_nu;
; unsigned char       ac_bd_state;
; unsigned char 		state;  		  //软件位状态寄存器
; //state.0 正反转状态位					  			1正转    0反转 						  			
; //state.1 全速标志   								1全速    0正常
; //state.2 
; //state.3 启停                                      1启      0停
; //state.4 
; //state.5 
; //state.6 
; //state.7 
; unsigned char state_other;//软件位状态寄存器
; //state.2 显示方式									1流量    0转速
; //state.4 脚踏开关标志位  							1脉冲    0电平
; //state.5 外控方式        							1关      0开
; unsigned char       state0;		        //软件位状态寄存器0
; //state0.0 校正体积改变标志							1改变    0无改变	  
; //state0.1 电机abcd相工作状态位		   				1为ab相  0为cd相 
; //state0.2 测试模式使能位  				  			1使能    0禁止
; //state0.3 在旋转编码开关控制函数里是否为第一次旋转 1第一次,0连续
; //state0.4 定时分配标志								1分配    0停止
; //state0.5 接收消息有效标志
; //state0.6 显示            							1转速    0流量
; //state0.7 初始化启停                               1启      0停   
; extern unsigned char state2;    
; //state2.0 disable_data    1:输入数据无效  			0:有效;
; //state2.1 remote		   1:遥控输入有效  			0:本地输入有效
; //state2.2 				   1:外控关		            0:外控开
; //state2.3    		 	   1:键盘+10       	 		0:键盘+1  
; //state2.4				   1:允许输入数据			0:禁止输入数据 
; //state2.5				   1:允许					0:停机
; //state2.6 				   1:无外控模块             0:有外控模块
; //state2.7 p99			   1:P99指令使能   	 		0:禁止
; extern unsigned char state1;
; //state1.7                 1:电流					0:电压
; unsigned char in_out_state;
; unsigned char in_out_number;
; unsigned char wrong;
; /*
; 0正常
; 1数值下溢出
; 2数值上溢出
; 3
; */
; unsigned char counter;
; unsigned int speed_pull;
; extern unsigned char pump_tab;
; 
; //定义中断向量
; #pragma interrupt_handler time1_int:iv_TIMER1_COMPA
; #pragma interrupt_handler time2_int:iv_TIMER2_COMP
; #pragma interrupt_handler pull_int:iv_INT0
; 
; 
; /******************************************************
; D/A出细分波形中断函数(定时器1比较匹配中断)
; ******************************************************/
; void time1_int(void)
; {
	.dbline 133
; unsigned char i;
; unsigned char j;
; if (micros_nu==micros_nu0)
	lds R2,_micros_nu0
	lds R3,_micros_nu
	cp R3,R2
	brne L2
	.dbline 134
;    {time_da0=time_da;}
	.dbline 134
	lds R2,_time_da
	lds R3,_time_da+1
	sts _time_da0+1,R3
	sts _time_da0,R2
	.dbline 134
	xjmp L3
L2:
	.dbline 136
; else 
;    {if (da_counter==128)
	.dbline 136
	lds R24,_da_counter
	cpi R24,128
	brne L4
	.dbline 137
;        {
	.dbline 138
; 	   micros_nu0=micros_nu;
	lds R2,_micros_nu
	sts _micros_nu0,R2
	.dbline 139
; 	   time_da0=time_da;
	lds R2,_time_da
	lds R3,_time_da+1
	sts _time_da0+1,R3
	sts _time_da0,R2
	.dbline 140
; 	   }
L4:
	.dbline 141
;    }
L3:
	.dbline 142
; OCR1A=time_da0;
	lds R2,_time_da0
	lds R3,_time_da0+1
	out 0x2b,R3
	out 0x2a,R2
	.dbline 143
; if (da_counter>=128)
	lds R24,_da_counter
	cpi R24,128
	brlo L6
	.dbline 144
;    {da_counter=0;} 
	.dbline 144
	clr R2
	sts _da_counter,R2
	.dbline 144
L6:
	.dbline 145
; i=tabsin[da_counter];
	ldi R24,<_tabsin
	ldi R25,>_tabsin
	lds R30,_da_counter
	clr R31
	add R30,R24
	adc R31,R25
	lpm R18,Z
	.dbline 146
; j=tabcos[da_counter];
	ldi R24,<_tabcos
	ldi R25,>_tabcos
	lds R30,_da_counter
	clr R31
	add R30,R24
	adc R31,R25
	lpm R16,Z
	.dbline 147
; PORTD&=~(1<<DA_CS);
	cbi 0x12,6
	.dbline 148
; PORTD&=~(1<<DA_AB);
	cbi 0x12,7
	.dbline 149
; DATA_OUT=i;                     //送正弦值
	out 0x18,R18
	.dbline 150
; asm("nop");
	nop
	.dbline 151
; PORTA&=~(1<<DA_WR);
	cbi 0x1b,1
	.dbline 152
; PORTA|=(1<<DA_WR);
	sbi 0x1b,1
	.dbline 153
; PORTD|=(1<<DA_AB);
	sbi 0x12,7
	.dbline 154
; DATA_OUT=j;                     //送正弦值
	out 0x18,R16
	.dbline 155
; asm("nop");
	nop
	.dbline 156
; PORTA&=~(1<<DA_WR);
	cbi 0x1b,1
	.dbline 157
; PORTA|=(1<<DA_WR);
	sbi 0x1b,1
	.dbline 158
; PORTD|=(1<<DA_CS);
	sbi 0x12,6
	.dbline 159
; if ((state|0b11111110)==0b11111110)           //判断正反转
	lds R24,_state
	ori R24,254
	cpi R24,254
	brne L8
	.dbline 160
;   {											  //正转
	.dbline 161
;   if (ac_bd_state==0)         //ac相处理
	lds R2,_ac_bd_state
	tst R2
	brne L10
	.dbline 162
;     {
	.dbline 163
; 	if (da_counter==0)
	lds R2,_da_counter
	tst R2
	brne L12
	.dbline 164
; 	   {
	.dbline 165
; 	   PORTC&=~(1<<DA_SIN);
	cbi 0x15,7
	.dbline 166
; 	   PORTC&=~(1<<DA_COS);
	cbi 0x15,6
	.dbline 167
; 	   ac_bd_state=1;
	ldi R24,1
	sts _ac_bd_state,R24
	.dbline 168
; 	   }
	xjmp L9
L12:
	.dbline 170
; 	else 
; 	   {
	.dbline 171
; 	   if (da_counter==64)
	lds R24,_da_counter
	cpi R24,64
	brne L9
	.dbline 172
; 	   	  {
	.dbline 173
; 		  PORTC&=~(1<<DA_SIN);
	cbi 0x15,7
	.dbline 174
; 	      PORTC|=(1<<DA_COS);
	sbi 0x15,6
	.dbline 175
; 		  }
	.dbline 176
; 	   }	
	.dbline 177
; 	}
	xjmp L9
L10:
	.dbline 179
;   else 			   		  			 //bd相处理
;     {
	.dbline 180
; 	if (da_counter==0)
	lds R2,_da_counter
	tst R2
	brne L16
	.dbline 181
; 	   {
	.dbline 182
; 	   PORTC|=(1<<DA_SIN);
	sbi 0x15,7
	.dbline 183
; 	   PORTC|=(1<<DA_COS);
	sbi 0x15,6
	.dbline 184
; 	   ac_bd_state=0;
	clr R2
	sts _ac_bd_state,R2
	.dbline 185
; 	   }
	xjmp L9
L16:
	.dbline 187
; 	else 
; 	   {
	.dbline 188
; 	   if (da_counter==64)
	lds R24,_da_counter
	cpi R24,64
	brne L9
	.dbline 189
; 	   	  {
	.dbline 190
; 		  PORTC|=(1<<DA_SIN);
	sbi 0x15,7
	.dbline 191
; 	      PORTC&=~(1<<DA_COS);
	cbi 0x15,6
	.dbline 192
; 		  }
	.dbline 193
; 	   }		 
	.dbline 194
;     }
	.dbline 195
;   }
	xjmp L9
L8:
	.dbline 197
; else  		  	   		  			 //反转
;   {
	.dbline 198
;   if (ac_bd_state==0)         //ac相处理
	lds R2,_ac_bd_state
	tst R2
	brne L20
	.dbline 199
;     {
	.dbline 200
; 	if (da_counter==0)
	lds R2,_da_counter
	tst R2
	brne L22
	.dbline 201
; 	   {
	.dbline 202
; 	   PORTC&=~(1<<DA_SIN);
	cbi 0x15,7
	.dbline 203
; 	   PORTC|=(1<<DA_COS);
	sbi 0x15,6
	.dbline 204
; 	   ac_bd_state=1;
	ldi R24,1
	sts _ac_bd_state,R24
	.dbline 205
; 	   }
	xjmp L21
L22:
	.dbline 207
; 	else 
; 	   {
	.dbline 208
; 	   if (da_counter==64)
	lds R24,_da_counter
	cpi R24,64
	brne L21
	.dbline 209
; 	   	  {
	.dbline 210
; 		  PORTC&=~(1<<DA_SIN);
	cbi 0x15,7
	.dbline 211
; 	      PORTC&=~(1<<DA_COS);
	cbi 0x15,6
	.dbline 212
; 		  }
	.dbline 213
; 	   }	
	.dbline 214
; 	}
	xjmp L21
L20:
	.dbline 216
;   else 			   		  			 //bd相处理
;     {
	.dbline 217
; 	if (da_counter==0)
	lds R2,_da_counter
	tst R2
	brne L26
	.dbline 218
; 	   {
	.dbline 219
; 	   PORTC|=(1<<DA_SIN);
	sbi 0x15,7
	.dbline 220
; 	   PORTC&=~(1<<DA_COS);
	cbi 0x15,6
	.dbline 221
; 	   ac_bd_state=0;
	clr R2
	sts _ac_bd_state,R2
	.dbline 222
; 	   }
	xjmp L27
L26:
	.dbline 224
; 	else 
; 	   {
	.dbline 225
; 	   if (da_counter==64)
	lds R24,_da_counter
	cpi R24,64
	brne L28
	.dbline 226
; 	   	  {
	.dbline 227
; 		  PORTC|=(1<<DA_SIN);
	sbi 0x15,7
	.dbline 228
; 	      PORTC|=(1<<DA_COS);
	sbi 0x15,6
	.dbline 229
; 		  }
L28:
	.dbline 230
; 	   }		 
L27:
	.dbline 231
;     }
L21:
	.dbline 232
;   }
L9:
	.dbline 233
; if (micros_nu0==32)	 	  			 		   	//根据细分数对地址指针步进
	lds R24,_micros_nu0
	cpi R24,32
	brne L30
	.dbline 234
;    {da_counter++;}
	.dbline 234
	lds R24,_da_counter
	subi R24,255    ; addi 1
	sts _da_counter,R24
	.dbline 234
	xjmp L31
L30:
	.dbline 236
; else
;    {

⌨️ 快捷键说明

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