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

📄 coder.s

📁 m8改造4VF遥控器
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module coder.c
	.area data(ram, con, rel)
_ch_time::
	.blkb 2
	.area idata
	.word 1000
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.word 1000
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.word 1000
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.word 1000
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.word 1000
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.word 1000
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.word 1000
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.word 1000
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.word 1000
	.area data(ram, con, rel)
	.dbfile D:\AVR程序\简易编码系统\coder.c
	.dbsym e ch_time _ch_time A[18:9]i
_ch_counter::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\AVR程序\简易编码系统\coder.c
	.dbsym e ch_counter _ch_counter c
_input::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\AVR程序\简易编码系统\coder.c
	.dbsym e input _input c
_train::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\AVR程序\简易编码系统\coder.c
	.dbsym e train _train c
	.area text(rom, con, rel)
	.dbfile D:\AVR程序\简易编码系统\coder.c
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 49
; //中断方式发送PWM脉冲,负脉冲,变化范围为1MS~2MS。INT0为教练接口输入负脉冲,INT1为教练接口2,输入正脉冲后自动翻转,
; //外部中断接口打开上拉。隔离脉冲为500US
; //有一个教练允许开关,打开后进入死循环,并允许外部中断,前提条件是有信号,用定时器0进行信号有无判断
; //定时器1采用比较匹配方式触发中断进行信号发送
; 
; 
; #include <iom8v.h>
; #include <macros.h>
; 
; #define Uchar unsigned char
; #define Uint unsigned int
; 
; 
; #define nop() asm("nop")
; #define _nop_() asm("nop")
; 
; 
; 
; #define PB PORTB
; #define PC PORTC
; #define PD PORTD
;  
; #define IN0 PIND&0x04
; #define IN1 PIND&0x08
; 
; #define LEDH PB|=0x01
; #define LEDL PB&=~0x01
; 
; #define BUTTON1 PINB&0x02
; #define BUTTON2 PINB&0x04
; #define BUTTON3 PINB&0x08
; #define BUTTON4 PINB&0x10
; #define BUTTON5 PINB&0x20
; 
; #define OUTH PD|=0x80
; #define OUTL PD&=~0x80
; 
; #define LOW_TIME 400
; #define SWH_time 900
; #define SWL_time 100
; 
; Uint ch_time[9]={1000,1000,1000,1000,1000,1000,1000,1000,1000};//输出用
; Uint time[9];//输出缓存
; Uchar ch_counter=0;//通道计数,用来与数据采集同步
; Uchar input=0;//信号输入有无标志
; Uchar train=0;//训练开始表示,防止切换时发生抖舵
; 
; void port_init(void)
; {
	.dbline 50
;  PORTB = 0x3E;
	ldi R24,62
	out 0x18,R24
	.dbline 51
;  DDRB  = 0x01;
	ldi R24,1
	out 0x17,R24
	.dbline 52
;  PORTC = 0x00; //m103 output only
	clr R2
	out 0x15,R2
	.dbline 53
;  DDRC  = 0x00;
	out 0x14,R2
	.dbline 54
;  PORTD = 0x0C;
	ldi R24,12
	out 0x12,R24
	.dbline 55
;  DDRD  = 0x80;
	ldi R24,128
	out 0x11,R24
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e timer0_init _timer0_init fV
	.even
_timer0_init::
	.dbline -1
	.dbline 64
; }
; 
; //c输入
; 
; //TIMER0 initialize - prescale:1024
; // desired value: 1Hz
; // actual value: Out of range
; void timer0_init(void)
; {
	.dbline 65
;  TCCR0 = 0x00; //stop
	clr R2
	out 0x33,R2
	.dbline 66
;  TCNT0 = 0x00 /*INVALID SETTING*/; //set count
	out 0x32,R2
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 18
	rjmp _timer0_ovf_isr
	.area text(rom, con, rel)
	.dbfile D:\AVR程序\简易编码系统\coder.c
	.dbfunc e timer0_ovf_isr _timer0_ovf_isr fV
	.even
_timer0_ovf_isr::
	st -y,R2
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 72
;  //TCCR0 = 0x05; //start timer
; }
; 
; #pragma interrupt_handler timer0_ovf_isr:10
; void timer0_ovf_isr(void)
; {
	.dbline 73
;  input=0;
	clr R2
	sts _input,R2
	.dbline 74
;  train=0;
	sts _train,R2
	.dbline -2
L3:
	ld R2,y+
	out 0x3f,R2
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e timer1_init _timer1_init fV
	.even
_timer1_init::
	.dbline -1
	.dbline 82
; }
; 
; //TIMER1 initialize - prescale:8
; // WGM: 0) Normal, TOP=0xFFFF
; // desired value: 1Hz
; // actual value: Out of range
; void timer1_init(void)
; {
	.dbline 83
;  TCCR1B = 0x00; //stop
	clr R2
	out 0x2e,R2
	.dbline 84
;  TCNT1H = 0x00 /*INVALID SETTING*/; //setup
	out 0x2d,R2
	.dbline 85
;  TCNT1L = 0x00 /*INVALID SETTING*/;
	out 0x2c,R2
	.dbline 86
;  OCR1AH = 0x00 /*INVALID SETTING*/;
	out 0x2b,R2
	.dbline 87
;  OCR1AL = 0x00 /*INVALID SETTING*/;
	out 0x2a,R2
	.dbline 88
;  OCR1BH = 0x00 /*INVALID SETTING*/;
	out 0x29,R2
	.dbline 89
;  OCR1BL = 0x00 /*INVALID SETTING*/;
	out 0x28,R2
	.dbline 90
;  ICR1H  = 0x00 /*INVALID SETTING*/;
	out 0x27,R2
	.dbline 91
;  ICR1L  = 0x00 /*INVALID SETTING*/;
	out 0x26,R2
	.dbline 92
;  TCCR1A = 0x00;
	out 0x2f,R2
	.dbline 93
;  TCCR1B = 0x02; //start Timer
	ldi R24,2
	out 0x2e,R24
	.dbline -2
L4:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 12
	rjmp _timer1_compa_isr
	.area text(rom, con, rel)
	.dbfile D:\AVR程序\简易编码系统\coder.c
	.area data(ram, con, rel)
	.dbfile D:\AVR程序\简易编码系统\coder.c
L6:
	.blkb 1
	.area idata
	.byte 1
	.area data(ram, con, rel)
	.dbfile D:\AVR程序\简易编码系统\coder.c
	.area text(rom, con, rel)
	.dbfile D:\AVR程序\简易编码系统\coder.c
	.dbfunc e timer1_compa_isr _timer1_compa_isr fV
	.dbsym s output_static L6 c
;        counter -> R16
	.even
_timer1_compa_isr::
	st -y,R0
	st -y,R1
	st -y,R2
	st -y,R3
	st -y,R16
	st -y,R17
	st -y,R24
	st -y,R25
	st -y,R26
	st -y,R27
	st -y,R30
	st -y,R31
	in R0,0x3f
	st -y,R0
	.dbline -1
	.dbline 98
; }
; 
; #pragma interrupt_handler timer1_compa_isr:7
; void timer1_compa_isr(void)
; {
	.dbline 106
;  //compare occured TCNT1=OCR1A//本函数来自4Vf改装系统,有部分改变
;  static Uchar output_static=1;//输出状态,0代表即将输出一个低电平,1代表即将输出一个高电平
;                            //第一次发信号先发一个低电平
;  	
; Uchar counter;//普通计数器用来拷贝数据
; 
; 					   
; output_static=!output_static;
	lds R2,L6
	tst R2
	brne L7
	ldi R16,1
	ldi R17,0
	rjmp L8
L7:
	clr R16
	clr R17
L8:
	sts L6,R16
	.dbline 108
;   
; switch(output_static)
	clr R17
	cpi R16,0
	cpc R16,R17
	breq L12
X0:
	cpi R16,1
	ldi R30,0
	cpc R17,R30
	breq L15
	rjmp L9
X1:
	.dbline 109
; {
L12:
	.dbline 110
; case 0:OUTH;
	sbi 0x12,7
	.dbline 111
;        TCNT1=0;//定时器清零
	clr R2
	clr R3
	out 0x2d,R3
	out 0x2c,R2
	.dbline 112
; 	   OCR1A=LOW_TIME;
	ldi R24,400
	ldi R25,1
	out 0x2b,R25
	out 0x2a,R24
	.dbline 113
; 	   if(ch_counter==9)ch_counter=0;//计数清零同步放行
	lds R24,_ch_counter
	cpi R24,9
	breq X2
	rjmp L10
X2:
	.dbline 113
	sts _ch_counter,R2
	.dbline 114
; break;
	rjmp L10
L15:
	.dbline 116
; 
; case 1:OUTL;
	cbi 0x12,7
	.dbline 117
;        TCNT1=0;//定时器清零
	clr R2
	clr R3
	out 0x2d,R3
	out 0x2c,R2
	.dbline 118
; 	   OCR1A=ch_time[ch_counter];  
	lds R2,_ch_counter
	ldi R24,2
	mul R24,R2
	movw R30,R0
	ldi R24,<_ch_time
	ldi R25,>_ch_time
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	out 0x2b,R3
	out 0x2a,R2
	.dbline 119
; 	        if(ch_counter==8)//最后一个高电平是同步电平
	lds R24,_ch_counter
	cpi R24,8
	brne L16
	.dbline 120
; 	   {
	.dbline 121
; 	      for(counter=0;counter<=8;counter++)
	clr R16
	rjmp L21
L18:
	.dbline 122
	.dbline 123
	ldi R24,2
	mul R24,R16
	ldi R24,<_time
	ldi R25,>_time
	movw R30,R0
	add R30,R24
	adc R31,R25
	ldd R24,z+0
	ldd R25,z+1
	subi R24,168  ; offset = 600
	sbci R25,253
	ldi R30,<_ch_time
	ldi R31,>_ch_time
	movw R26,R0
	add R26,R30
	adc R27,R31
	st x+,R24
	st x,R25
	.dbline 125
L19:
	.dbline 121
	inc R16
L21:
	.dbline 121
	ldi R24,8
	cp R24,R16
	brsh L18
	.dbline 126
; 	      {
; 	      ch_time[counter]=time[counter]+600;
; 		  
; 	      }
; 	   }
L16:
	.dbline 127
; 	   ch_counter++;
	lds R24,_ch_counter
	subi R24,255    ; addi 1
	sts _ch_counter,R24
	.dbline 128
; }// switch(output_static)
L9:
L10:
	.dbline -2
L5:
	ld R0,y+
	out 0x3f,R0
	ld R31,y+
	ld R30,y+
	ld R27,y+
	ld R26,y+
	ld R25,y+
	ld R24,y+
	ld R17,y+
	ld R16,y+
	ld R3,y+
	ld R2,y+
	ld R1,y+
	ld R0,y+
	.dbline 0 ; func end
	reti
	.dbsym r counter 16 c
	.dbend
	.dbfunc e adc_init _adc_init fV
	.even
_adc_init::
	.dbline -1
	.dbline 137
; 
; }//void timer1_compa_isr(void)
; 
; 
; 
; //ADC initialize
; // Conversion time: 104uS
; void adc_init(void)
; {
	.dbline 138
;  ADCSR = 0x00; //disable adc
	clr R2
	out 0x6,R2
	.dbline 139
;  ADMUX = 0x00; //select adc input 0
	out 0x7,R2
	.dbline 140
;  ACSR  = 0x80;
	ldi R24,128
	out 0x8,R24
	.dbline 141
;  ADCSR = 0x86;
	ldi R24,134
	out 0x6,R24
	.dbline -2
L22:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e watchdog_init _watchdog_init fV
	.even
_watchdog_init::
	.dbline -1
	.dbline 147
; }
; 
; //Watchdog initialize
; // prescale: 32K 
; void watchdog_init(void)
; {
	.dbline 148
;  WDR(); //this prevents a timout on enabling
	wdr
	.dbline 149
;  WDTCR = 0x18;
	ldi R24,24
	out 0x21,R24
	.dbline 150
;  WDTCR = 0x09; //WATCHDOG ENABLED - dont forget to issue WDRs
	ldi R24,9
	out 0x21,R24
	.dbline -2
L23:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 158
;  
; }
; 
; 
; 
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
	.dbline 160
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 162
;  
;  port_init();
	rcall _port_init
	.dbline 163
;  timer0_init();
	rcall _timer0_init
	.dbline 164
;  timer1_init();
	rcall _timer1_init
	.dbline 165
;  adc_init();
	rcall _adc_init
	.dbline 166
;  OSCCAL=0xb3;
	ldi R24,179
	out 0x31,R24
	.dbline 167
;  watchdog_init();
	rcall _watchdog_init
	.dbline 168
;  MCUCR = 0x05;
	ldi R24,5
	out 0x35,R24
	.dbline 170
;  //GICR//中断开关应在MAIN中用开关和信号有无控制
;  GICR  = 0x00;
	clr R2
	out 0x3b,R2
	.dbline 171
;  TIMSK = 0x11; //timer interrupt sources
	ldi R24,17
	out 0x39,R24
	.dbline 172
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
L24:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 2
	rjmp _int0_isr
	.area text(rom, con, rel)
	.dbfile D:\AVR程序\简易编码系统\coder.c
	.dbfunc e int0_isr _int0_isr fV
	.even
_int0_isr::
	st -y,R2
	st -y,R16
	st -y,R17
	st -y,R24
	st -y,R30
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 180
;  //all peripherals are now initialized
; }
; 
; 
; 
; #pragma interrupt_handler int0_isr:2
; void int0_isr(void)
; {
	.dbline 182
;  //external interupt on INT0 负输入
;  TCNT0 = 0x00 ;//有信号
	clr R2
	out 0x32,R2
	.dbline 183
;  input=1;
	ldi R24,1
	sts _input,R24
	.dbline 184
;  if(train)//先不忙发送
	lds R2,_train
	tst R2
	breq L26
	.dbline 185
;  switch(IN0)
	in R16,0x10
	clr R17
	andi R16,4
	andi R17,0
	cpi R16,0
	cpc R16,R17
	breq L31
X3:
	cpi R16,0
	ldi R30,0
	cpc R17,R30
	brlt L28
L33:
	cpi R16,4
	ldi R30,0
	cpc R17,R30
	breq L32
	rjmp L28
X4:
	.dbline 186
;  {
L31:
	.dbline 188
;  case 0:
;  OUTL;
	cbi 0x12,7
	.dbline 189
;  break;
	rjmp L29
L32:
	.dbline 191
;  case 0x04:
;  OUTH;
	sbi 0x12,7
	.dbline 192
;  }
L28:
L29:
L26:
	.dbline -2
L25:
	ld R2,y+
	out 0x3f,R2
	ld R30,y+
	ld R24,y+
	ld R17,y+
	ld R16,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbend
	.area vector(rom, abs)
	.org 4
	rjmp _int1_isr
	.area text(rom, con, rel)
	.dbfile D:\AVR程序\简易编码系统\coder.c
	.dbfunc e int1_isr _int1_isr fV
	.even
_int1_isr::
	st -y,R2
	st -y,R16
	st -y,R17
	st -y,R24
	st -y,R30
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 197
; }
; 
; #pragma interrupt_handler int1_isr:3
; void int1_isr(void)
; {
	.dbline 199
;  //external interupt on INT1 正输入自动反向
;  TCNT0 = 0x00 ;//有信号

⌨️ 快捷键说明

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