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

📄 motor.s

📁 步进电机驱动程序。ICCAVR开发。ATMEGA8
💻 S
字号:
	.module _251.c
	.area data(ram, con, rel)
_MotorBlocked::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\prog251\Motortest\251.c
	.dbsym e MotorBlocked _MotorBlocked c
_SpeedMotorCurrent::
	.blkb 2
	.area idata
	.word 0
	.area data(ram, con, rel)
	.dbfile D:\prog251\Motortest\251.c
	.dbsym e SpeedMotorCurrent _SpeedMotorCurrent I
_SpeedMotorSetting::
	.blkb 2
	.area idata
	.word 2880
	.area data(ram, con, rel)
	.dbfile D:\prog251\Motortest\251.c
	.dbsym e SpeedMotorSetting _SpeedMotorSetting I
	.area text(rom, con, rel)
	.dbfile D:\prog251\Motortest\251.c
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 27
; //ICC-AVR application builder : 2008-7-3 10:08:15
; // Target : M8
; // Crystal: 4.0000Mhz
; 
; #include <iom8v.h>
; #include <macros.h>
; 
; #define uchar unsigned char
; #define unint unsigned int
; #define MaxAngle 2880
; 
; 
; void motor(void);
; 
; //GLOBAL VARIABLES
; //SIGNALS
; uchar MotorBlocked = 0;
; 
; //MOTOR POSITION
; SpeedMotorCurrent = 0;
; SpeedMotorSetting = 2880; //test
; 
; 
; 
; 
; void port_init(void)
; {
	.dbline 28
;  PORTB = 0x04;
	ldi R24,4
	out 0x18,R24
	.dbline 29
;  DDRB  = 0xef;
	ldi R24,239
	out 0x17,R24
	.dbline 30
;  PORTC = 0x00; //m103 output only
	clr R2
	out 0x15,R2
	.dbline 31
;  DDRC  = 0x40;
	ldi R24,64
	out 0x14,R24
	.dbline 32
;  PORTD = 0x00;
	out 0x12,R2
	.dbline 33
;  DDRD  = 0x80;
	ldi R24,128
	out 0x11,R24
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e timer1_init _timer1_init fV
	.even
_timer1_init::
	.dbline -1
	.dbline 41
; }
; 
; //TIMER1 initialize - prescale:8
; // WGM: 0) Normal, TOP=0xFFFF
; // desired value: 0.1Sec
; // actual value:  0.100Sec (0.0%)
; void timer1_init(void)
; {
	.dbline 42
;  TCCR1B = 0x00; //stop
	clr R2
	out 0x2e,R2
	.dbline 43
;  TCNT1H = 0xF0; //setup
	ldi R24,240
	out 0x2d,R24
	.dbline 44
;  TCNT1L = 0xBE;
	ldi R24,190
	out 0x2c,R24
	.dbline 47
; // TCNT1H = 0x67; //setup
; // TCNT1L = 0x6A;
;  OCR1AH = 0xC3;
	ldi R24,195
	out 0x2b,R24
	.dbline 48
;  OCR1AL = 0x50;
	ldi R24,80
	out 0x2a,R24
	.dbline 49
;  OCR1BH = 0xC3;
	ldi R24,195
	out 0x29,R24
	.dbline 50
;  OCR1BL = 0x50;
	ldi R24,80
	out 0x28,R24
	.dbline 51
;  ICR1H  = 0xC3;
	ldi R24,195
	out 0x27,R24
	.dbline 52
;  ICR1L  = 0x50;
	ldi R24,80
	out 0x26,R24
	.dbline 53
;  TCCR1A = 0x00;
	out 0x2f,R2
	.dbline 54
;  TCCR1B = 0x05; //start Timer
	ldi R24,5
	out 0x2e,R24
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 16
	rjmp _timer1_ovf_isr
	.area text(rom, con, rel)
	.dbfile D:\prog251\Motortest\251.c
	.dbfunc e timer1_ovf_isr _timer1_ovf_isr fV
	.even
_timer1_ovf_isr::
	st -y,R24
	in R24,0x3f
	st -y,R24
	.dbline -1
	.dbline 59
; }
; 
; #pragma interrupt_handler timer1_ovf_isr:9
; void timer1_ovf_isr(void)
; {
	.dbline 61
;  //TIMER1 has overflowed
;  TCNT1H = 0xF0; //reload counter high value
	ldi R24,240
	out 0x2d,R24
	.dbline 62
;  TCNT1L = 0xBE; //reload counter low value
	ldi R24,190
	out 0x2c,R24
	.dbline -2
L3:
	ld R24,y+
	out 0x3f,R24
	ld R24,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e timer2_init _timer2_init fV
	.even
_timer2_init::
	.dbline -1
	.dbline 74
; // TCNT1H = 0x67; //setup
; // TCNT1L = 0x6A;
;  
; 
; }
; 
; //TIMER2 initialize - prescale:32
; // WGM: Normal
; // desired value: 1KHz
; // actual value:  1.000KHz (0.0%)
; void timer2_init(void)
; {
	.dbline 75
;  TCCR2 = 0x00; //stop
	clr R2
	out 0x25,R2
	.dbline 76
;  ASSR  = 0x00; //set async mode
	out 0x22,R2
	.dbline 77
;  TCNT2 = 0x83; //setup
	ldi R24,131
	out 0x24,R24
	.dbline 78
;  OCR2  = 0x7D;
	ldi R24,125
	out 0x23,R24
	.dbline 79
;  TCCR2 = 0x03; //start
	ldi R24,3
	out 0x25,R24
	.dbline -2
L4:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 8
	rjmp _timer2_ovf_isr
	.area text(rom, con, rel)
	.dbfile D:\prog251\Motortest\251.c
	.dbfunc e timer2_ovf_isr _timer2_ovf_isr fV
	.even
_timer2_ovf_isr::
	st -y,R2
	st -y,R24
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 84
; }
; 
; #pragma interrupt_handler timer2_ovf_isr:5
; void timer2_ovf_isr(void)
; {
	.dbline 85
;  TCNT2 = 0x83; //reload counter value
	ldi R24,131
	out 0x24,R24
	.dbline 88
; // TCNT2 = 0x07; //reload counter value
;  //unblock motor
;   MotorBlocked = 0;
	clr R2
	sts _MotorBlocked,R2
	.dbline 90
;  //TEST
;  PORTB ^= BIT(2);	 
	ldi R24,4
	in R2,0x18
	eor R2,R24
	out 0x18,R2
	.dbline -2
L5:
	ld R2,y+
	out 0x3f,R2
	ld R24,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e spi_init _spi_init fV
	.even
_spi_init::
	.dbline -1
	.dbline 97
; 
; }
; 
; //SPI initialize
; // clock rate: 250000hz
; void spi_init(void)
; {
	.dbline 98
;  SPCR = 0x51; //setup SPI
	ldi R24,81
	out 0xd,R24
	.dbline 99
;  SPSR = 0x00; //setup SPI
	clr R2
	out 0xe,R2
	.dbline -2
L6:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e adc_init _adc_init fV
	.even
_adc_init::
	.dbline -1
	.dbline 105
; }
; 
; //ADC initialize
; // Conversion time: 104uS
; void adc_init(void)
; {
	.dbline 106
;  ADCSR = 0x00; //disable adc
	clr R2
	out 0x6,R2
	.dbline 107
;  ADMUX = 0x00; //select adc input 0
	out 0x7,R2
	.dbline 108
;  ACSR  = 0x80;
	ldi R24,128
	out 0x8,R24
	.dbline 109
;  ADCSR = 0xED;
	ldi R24,237
	out 0x6,R24
	.dbline -2
L7:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 28
	rjmp _adc_isr
	.area text(rom, con, rel)
	.dbfile D:\prog251\Motortest\251.c
	.dbfunc e adc_isr _adc_isr fV
	.even
_adc_isr::
	.dbline -1
	.dbline 114
; }
; 
; #pragma interrupt_handler adc_isr:15
; void adc_isr(void)
; {
	.dbline -2
L8:
	.dbline 0 ; func end
	reti
	.dbend
	.area vector(rom, abs)
	.org 2
	rjmp _int0_isr
	.area text(rom, con, rel)
	.dbfile D:\prog251\Motortest\251.c
	.dbfunc e int0_isr _int0_isr fV
	.even
_int0_isr::
	.dbline -1
	.dbline 122
;  //conversion complete, read value (int) using...
;  // value=ADCL;            //Read 8 low bits first (important)
;  // value|=(int)ADCH << 8; //read 2 high bits and shift into top byte
; }
; 
; #pragma interrupt_handler int0_isr:2
; void int0_isr(void)
; {
	.dbline -2
L9:
	.dbline 0 ; func end
	reti
	.dbend
	.area vector(rom, abs)
	.org 4
	rjmp _int1_isr
	.area text(rom, con, rel)
	.dbfile D:\prog251\Motortest\251.c
	.dbfunc e int1_isr _int1_isr fV
	.even
_int1_isr::
	.dbline -1
	.dbline 128
;  //external interupt on INT0
; }
; 
; #pragma interrupt_handler int1_isr:3
; void int1_isr(void)
; {
	.dbline -2
L10:
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 134
;  //external interupt on INT1
; }
; 
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
	.dbline 136
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 137
;  port_init();
	rcall _port_init
	.dbline 138
;  timer1_init();
	rcall _timer1_init
	.dbline 139
;  timer2_init();
	rcall _timer2_init
	.dbline 140
;  spi_init();
	rcall _spi_init
	.dbline 141
;  adc_init();
	rcall _adc_init
	.dbline 143
; 
;  MCUCR = 0x0F;
	ldi R24,15
	out 0x35,R24
	.dbline 144
;  GICR  = 0xC0;
	ldi R24,192
	out 0x3b,R24
	.dbline 145
;  TIMSK = 0x44; //timer interrupt sources
	ldi R24,68
	out 0x39,R24
	.dbline 146
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
L11:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	.dbline -1
	.dbline 152
;  //all peripherals are now initialized
; }
; 
; //
; void main(void)
; {
	.dbline 153
;  init_devices();
	rcall _init_devices
	rjmp L14
L13:
	.dbline 156
;  //insert your functional code here...
;  while(1)
;  {
	.dbline 157
;     if(MotorBlocked==0)
	lds R2,_MotorBlocked
	tst R2
	brne L16
	.dbline 158
; 	  motor();
	rcall _motor
L16:
	.dbline 159
L14:
	.dbline 155
	rjmp L13
X0:
	.dbline -2
L12:
	.dbline 0 ; func end
	ret
	.dbend
	.area data(ram, con, rel)
	.dbfile D:\prog251\Motortest\251.c
_IOWord::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\prog251\Motortest\251.c
	.dbsym e IOWord _IOWord c
	.area text(rom, con, rel)
	.dbfile D:\prog251\Motortest\251.c
	.dbfunc e motor _motor fV
;          delay -> <dead>
;  anticlockwise -> R16
;      clockwise -> R16
	.even
_motor::
	.dbline -1
	.dbline 169
;  }
; 	  
; }
; 
; uchar IOWord = 0x00;
; 
; //===============================================
; //=============MOTOR SUBROUTINE=================
; //================================================
; void motor(void)
; {
	.dbline 170
;  	 uchar clockwise = 0x00;//test
	clr R16
	.dbline 171
; 	 uchar anticlockwise = 0;
	.dbline 185
; /* 	 //CALCULATE THE DIRECTION OF ALL MOTOR
; 	 if(SpeedMotorCurrent<SpeedMotorSetting)
; 	 {	 	 
; 	//   SpeedMotorCurrent++;
; 	   clockwise |=BIT(1); //SPEED invert
; 	 }
; 	 else if (SpeedMotorCurrent>SpeedMotorSetting)
; 	 {
; 	//   SpeedMotorCurrent--;
; 	   anticlockwise |= BIT(1); //SPEED invert
; 	 }
; */
; 	 int delay;
; 	 PORTB ^=BIT(1);
	ldi R24,2
	in R2,0x18
	eor R2,R24
	out 0x18,R2
	.dbline 189
; //	 PORTD ^=BIT(7);
; 	 //CLOCKWISE 
; 	   //set DAD1(PB7)
; 	   PORTB |= BIT(7);
	sbi 0x18,7
	.dbline 191
; 	   //set DAC1-8 through SPI
; 	   SPDR = 0x01;//clockwise;	//SPIOUTPUT
	ldi R24,1
	out 0xf,R24
L19:
	.dbline 192
L20:
	.dbline 192
; 	   while ( !(SPSR & BIT(7)) )	;		//wait  
	sbis 0xe,7
	rjmp L19
	.dbline 193
;  	   PORTB |= BIT(0);		 	//SET OUTCS
	sbi 0x18,0
	.dbline 194
; 	   _NOP();
	nop
	.dbline 195
; 	   PORTB &= ~BIT(0);		//CLEAR OUTCS
	cbi 0x18,0
	.dbline 197
; 	   //clear DAC1-8
; 	   SPDR = 0x00;	  		 //SPIOUTPUT
	clr R2
	out 0xf,R2
L22:
	.dbline 198
L23:
	.dbline 198
; 	   while ( !(SPSR & BIT(7)) )	;	  	//wait		
	sbis 0xe,7
	rjmp L22
	.dbline 199
; 	   PORTB |= BIT(0);		 	//SET OUTCS
	sbi 0x18,0
	.dbline 200
; 	   _NOP();
	nop
	.dbline 201
; 	   PORTB &= ~BIT(0);		//CLEAR OUTCS
	cbi 0x18,0
	.dbline 203
; 
; 	   SPDR = IOWord;	  		 //SPIOUTPUT
	lds R2,_IOWord
	out 0xf,R2
L25:
	.dbline 204
L26:
	.dbline 204
; 	   while ( !(SPSR & BIT(7)) )	;	  	//wait		
	sbis 0xe,7
	rjmp L25
	.dbline 205
; 	   PORTD = BIT(7);
	ldi R24,128
	out 0x12,R24
	.dbline 206
; 	   _NOP();
	nop
	.dbline 207
; 	   PORTD &= ~BIT(7);
	cbi 0x12,7
	.dbline 208
; 	   IOWord = ~IOWord;
	lds R2,_IOWord
	com R2
	sts _IOWord,R2
	.dbline 230
; 	 
; 	 //ANTICLOCKWISE
; 	 /*
; 	   //clear DAD1(PB7)
; 	   PORTB &= BIT(7);
; 	   //set DAC1-8 through SPI
; 	   SPDR = anticlockwise;	//SPIOUTPUT
; 	   while ( SPSR & BIT(7) )	;		//wait   
; 	   PORTB |= BIT(0);		 	//SET OUTCS
; 	   _NOP();
; 	   PORTB &= ~BIT(0);		//CLEAR OUTCS	   
; 	   //clear DAC1-8
; 	   SPDR = 0;	  		 	 //SPIOUTPUT
; 	   while ( SPSR & BIT(7) )	;	  	//wait		 
; 	   PORTB |= BIT(0);		 	//SET OUTCS
; 	   _NOP();
; 	   PORTB &= ~BIT(0);		//CLEAR OUTCS	   
; 	 //}
; 	 */
; 	 
; 	 //BLOCK
; 	 MotorBlocked = 1;
	ldi R24,1
	sts _MotorBlocked,R24
	.dbline -2
L18:
	.dbline 0 ; func end
	ret
	.dbsym l delay 1 I
	.dbsym r anticlockwise 16 c
	.dbsym r clockwise 16 c
	.dbend

⌨️ 快捷键说明

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