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

📄 icp.s

📁 AVR单片机的电机测速程序
💻 S
字号:
	.module ICP.C
	.area data(ram, con, rel)
_Cnt_Old::
	.blkb 2
	.area idata
	.word 0
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\www\桌面\motor_ce\ICP.C
	.dbsym e Cnt_Old _Cnt_Old i
_Cnt_New::
	.blkb 2
	.area idata
	.word 0
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\www\桌面\motor_ce\ICP.C
	.dbsym e Cnt_New _Cnt_New i
_Motor_Period::
	.blkb 2
	.area idata
	.word 0
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\www\桌面\motor_ce\ICP.C
	.dbsym e Motor_Period _Motor_Period i
_Cnt_Delta::
	.blkb 2
	.area idata
	.word 0
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\www\桌面\motor_ce\ICP.C
	.dbsym e Cnt_Delta _Cnt_Delta i
_Motor_Period_Hbyte::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\www\桌面\motor_ce\ICP.C
	.dbsym e Motor_Period_Hbyte _Motor_Period_Hbyte c
_Motor_Period_Lbyte::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\www\桌面\motor_ce\ICP.C
	.dbsym e Motor_Period_Lbyte _Motor_Period_Lbyte c
_Icr1L_Value::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\www\桌面\motor_ce\ICP.C
	.dbsym e Icr1L_Value _Icr1L_Value c
_Icr1H_Value::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\www\桌面\motor_ce\ICP.C
	.dbsym e Icr1H_Value _Icr1H_Value c
_Flag::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile C:\DOCUME~1\www\桌面\motor_ce\ICP.C
	.dbsym e Flag _Flag c
	.area text(rom, con, rel)
	.dbfile C:\DOCUME~1\www\桌面\motor_ce\ICP.C
	.dbfunc e Timer1_Init _Timer1_Init fV
	.even
_Timer1_Init::
	.dbline -1
	.dbline 17
; #include "includes.h"
; //---------------------------------------------------
; unsigned int  Cnt_Old=0;
; unsigned int  Cnt_New=0;
; 
; 
; unsigned int Motor_Period=0;
; unsigned int Cnt_Delta=0;
; unsigned char Motor_Period_Hbyte=0;
; unsigned char Motor_Period_Lbyte=0;
; unsigned char Icr1L_Value=0;
; unsigned char Icr1H_Value=0;
; unsigned char Flag=0;
; //--------------------------------------------------
; //Timer1初始化和ICP中断处理函数
; void Timer1_Init(void)
; {
	.dbline 18
; TCCR1B=0x00;             //停止计数器
	clr R2
	out 0x2e,R2
	.dbline 19
; TCCR1B=0b11000010;       //时钟为系统时钟8分频,为1us
	ldi R24,194
	out 0x2e,R24
	.dbline 20
; TIMSK|=0b00100000;       //使能ICP中断
	in R24,0x39
	ori R24,32
	out 0x39,R24
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 20
	jmp _Timer1_Capt_Isr
	.area text(rom, con, rel)
	.dbfile C:\DOCUME~1\www\桌面\motor_ce\ICP.C
	.dbfunc e Timer1_Capt_Isr _Timer1_Capt_Isr fV
	.even
_Timer1_Capt_Isr::
	xcall push_lset
	.dbline -1
	.dbline 25
; }
; /*******************************************/
; #pragma interrupt_handler Timer1_Capt_Isr:6
; void Timer1_Capt_Isr(void)
; {
	.dbline 26
; CLI();
	cli
	.dbline 27
; Icr1L_Value=ICR1L;
	in R2,0x26
	sts _Icr1L_Value,R2
	.dbline 28
; Icr1H_Value=ICR1H;
	in R2,0x27
	sts _Icr1H_Value,R2
	.dbline 29
; Cnt_New=Icr1L_Value+(256*Icr1H_Value);//获得现在计数值
	mov R18,R2
	clr R19
	ldi R16,256
	ldi R17,1
	xcall empy16s
	lds R2,_Icr1L_Value
	clr R3
	add R2,R16
	adc R3,R17
	sts _Cnt_New+1,R3
	sts _Cnt_New,R2
	.dbline 30
; if(Cnt_New>=Cnt_Old)       //判断新老计数值关系 
	lds R2,_Cnt_Old
	lds R3,_Cnt_Old+1
	lds R4,_Cnt_New
	lds R5,_Cnt_New+1
	cp R4,R2
	cpc R5,R3
	brlo L3
	.dbline 31
;  {                        //新值大于老值
	.dbline 32
;  Cnt_Delta=Cnt_New-Cnt_Old;
	sub R4,R2
	sbc R5,R3
	sts _Cnt_Delta+1,R5
	sts _Cnt_Delta,R4
	.dbline 33
;  }
	xjmp L4
L3:
	.dbline 35
; else                      //新值小于老值
;  {
	.dbline 36
;  Cnt_Delta=0xffff-Cnt_Old+Cnt_New;
	lds R2,_Cnt_Old
	lds R3,_Cnt_Old+1
	ldi R24,65535
	ldi R25,255
	sub R24,R2
	sbc R25,R3
	lds R2,_Cnt_New
	lds R3,_Cnt_New+1
	add R24,R2
	adc R25,R3
	sts _Cnt_Delta+1,R25
	sts _Cnt_Delta,R24
	.dbline 37
;  }
L4:
	.dbline 38
; Cnt_Old=Cnt_New;
	lds R2,_Cnt_New
	lds R3,_Cnt_New+1
	sts _Cnt_Old+1,R3
	sts _Cnt_Old,R2
	.dbline 39
; Motor_Period=Cnt_Delta*T0_CLK;//计算周期值
	lds R18,_Cnt_Delta
	lds R19,_Cnt_Delta+1
	ldi R16,1
	ldi R17,0
	xcall empy16s
	sts _Motor_Period+1,R17
	sts _Motor_Period,R16
	.dbline 40
; Motor_Period_Hbyte=((unsigned char)((Motor_Period& 0xff00)>>8));//计算周期高字节
	movw R24,R16
	andi R24,0
	mov R24,R25
	clr R25
	sts _Motor_Period_Hbyte,R24
	.dbline 41
; Motor_Period_Lbyte=((unsigned char)(Motor_Period&0x00ff));//计算周期低字节
	movw R24,R16
	andi R25,0
	sts _Motor_Period_Lbyte,R24
	.dbline 42
; if(Motor_Period_Lbyte=0xff)//避免与帧头重复
	ldi R24,255
	sts _Motor_Period_Lbyte,R24
	tst R24
	breq L5
	.dbline 43
;  {
	.dbline 44
;  Motor_Period_Lbyte=0xfe;
	ldi R24,254
	sts _Motor_Period_Lbyte,R24
	.dbline 45
;  }
L5:
	.dbline 46
; Flag++;
	lds R24,_Flag
	subi R24,255    ; addi 1
	sts _Flag,R24
	.dbline 47
; if(Flag%100==0)
	ldi R17,100
	mov R16,R24
	xcall mod8u
	tst R16
	brne L7
	.dbline 48
;  {
	.dbline 49
;  Usart_Tx(0xff);//上传帧头
	ldi R16,255
	xcall _Usart_Tx
	.dbline 50
;  Usart_Tx(Motor_Period_Hbyte);//上传周期高字节
	lds R16,_Motor_Period_Hbyte
	xcall _Usart_Tx
	.dbline 51
;  Usart_Tx(Motor_Period_Lbyte);//上传周期低字节
	lds R16,_Motor_Period_Lbyte
	xcall _Usart_Tx
	.dbline 52
;  }
L7:
	.dbline 53
; SEI();
	sei
	.dbline -2
L2:
	xcall pop_lset
	.dbline 0 ; func end
	reti
	.dbend

⌨️ 快捷键说明

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