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

📄 pulse_time.s

📁 单片机开发资料光盘-双龙-686M.zip
💻 S
字号:
	.module pulse_time.c
	.area vector(rom, abs)
	.org 20
	jmp _Icp_timer1
	.org 36
	jmp _Timer0
	.area code(ram, con, rel)
	.area lit(rom, con, rel)
_table::
	.byte 63,6
	.byte 91,'O
	.byte 'f,'m
	.byte 125,7
	.byte 127,'o
	.byte 'w,124
	.byte 57,94
	.byte 'y,'q
	.dbfile F:\李鹏飞\sl-avrad-m16\测脉宽\pulse_time.c
	.dbsym e table _table A[16:16]kc
	.area data(ram, con, rel)
	.dbfile F:\李鹏飞\sl-avrad-m16\测脉宽\pulse_time.c
_ledbuff::
	.blkb 2
	.area idata
	.byte 63,63
	.area data(ram, con, rel)
	.dbfile F:\李鹏飞\sl-avrad-m16\测脉宽\pulse_time.c
	.blkb 2
	.area idata
	.byte 63,63
	.area data(ram, con, rel)
	.dbfile F:\李鹏飞\sl-avrad-m16\测脉宽\pulse_time.c
	.blkb 2
	.area idata
	.byte 63,63
	.area data(ram, con, rel)
	.dbfile F:\李鹏飞\sl-avrad-m16\测脉宽\pulse_time.c
	.dbsym e ledbuff _ledbuff A[6:6]c
_i::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile F:\李鹏飞\sl-avrad-m16\测脉宽\pulse_time.c
	.dbsym e i _i c
	.area text(rom, con, rel)
	.dbfile F:\李鹏飞\sl-avrad-m16\测脉宽\pulse_time.c
	.dbfunc e delay_1ms _delay_1ms fV
;              i -> R16,R17
	.even
_delay_1ms::
	.dbline -1
	.dbline 30
; /******************************************/
; /*           广州天河双龙电子公司         */
; /*           http://www.sl.com.cn         */
; /*                 测脉宽程序             */
; /*   用跳线将PD6依次与PA0~PA7相连         */
; /*           作者:lpf@sl.com.cn           */
; /*             2003年8月28日              */
; /*  目标MCU:MEGA16   晶振:外部(EXT) 8MHZ  */
; /******************************************/
; 
; 
; #include<iom16v.h>
; #pragma interrupt_handler Icp_timer1:6
; //ICP中断入口地址
; #pragma interrupt_handler Timer0:10
; //定时器T0中断入口地址
; #pragma data:code
; //设置数据区为程序存储器
; //七段码译码字形表
; const unsigned char table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
; 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
; #pragma data:data
; //设置数据区回到数据存储器
; unsigned char ledbuff[]={0x3f,0x3f,0x3f,0x3f,0x3f,0x3f};//显示缓冲区
; unsigned int oldcount;
; unsigned int newcount;
; unsigned char i=0;
; //1MS延时程序
; void delay_1ms()
;   {
	.dbline 32
	ldi R16,1
	ldi R17,0
	xjmp L5
L2:
	.dbline 32
L3:
	.dbline 32
	subi R16,255  ; offset = 1
	sbci R17,255
L5:
	.dbline 32
;   unsigned int i;
;   for(i=1;i<1142;i++);
	cpi R16,118
	ldi R30,4
	cpc R17,R30
	brlo L2
	.dbline -2
	.dbline 33
;   }
L1:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 i
	.dbend
	.dbfunc e display _display fV
;              i -> R20
	.even
_display::
	xcall push_gset1
	.dbline -1
	.dbline 36
; //六路动态扫描显示  
; void display()
;   {
	.dbline 38
;   unsigned char i;
;   for(i=0;i<6;i++)
	clr R20
	xjmp L10
L7:
	.dbline 39
	.dbline 40
	ldi R24,<_ledbuff
	ldi R25,>_ledbuff
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	out 0x18,R2
	.dbline 41
	ldi R16,1
	mov R17,R20
	xcall lsl8
	mov R2,R16
	com R2
	out 0x12,R2
	.dbline 42
	xcall _delay_1ms
	.dbline 43
	ldi R16,1
	mov R17,R20
	xcall lsl8
	in R2,0x12
	or R2,R16
	out 0x12,R2
	.dbline 44
L8:
	.dbline 38
	inc R20
L10:
	.dbline 38
	cpi R20,6
	brlo L7
	.dbline -2
	.dbline 45
;       {
;       PORTB=ledbuff[i];
;       PORTD=~(1<<i);
;       delay_1ms();
;       PORTD|=(1<<i);
;       }
;   }
L6:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbend
	.dbfunc e hextobcd _hextobcd fV
;           temp -> R20
;              i -> R22
;          count -> R10,R11
	.even
_hextobcd::
	xcall push_gset3
	movw R10,R16
	.dbline -1
	.dbline 48
; //将COUNT十六进制数据转换为LED七段码
; void hextobcd(unsigned int count)
;   {
	.dbline 50
;   unsigned char i,temp;
;   for(i=0;i<6;i++)
	clr R22
	xjmp L15
L12:
	.dbline 51
	.dbline 52
	ldi R18,10
	ldi R19,0
	movw R16,R10
	xcall mod16u
	mov R20,R16
	.dbline 53
	ldi R24,<_table
	ldi R25,>_table
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	lpm R30,Z
	ldi R24,<_ledbuff
	ldi R25,>_ledbuff
	mov R26,R22
	clr R27
	add R26,R24
	adc R27,R25
	st x,R30
	.dbline 54
	ldi R18,10
	ldi R19,0
	movw R16,R10
	xcall div16u
	movw R10,R16
	.dbline 55
L13:
	.dbline 50
	inc R22
L15:
	.dbline 50
	cpi R22,6
	brlo L12
	.dbline -2
	.dbline 56
;       {
;       temp=count%10;
;       ledbuff[i]=table[temp];
;       count=count/10;
;       }
;   }
L11:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r temp 20 c
	.dbsym r i 22 c
	.dbsym r count 10 i
	.dbend
	.dbfunc e mcu_init _mcu_init fV
	.even
_mcu_init::
	.dbline -1
	.dbline 59
; //MCU初始化
; void mcu_init()
;   {
	.dbline 60
;   DDRA=0XFF;
	ldi R24,255
	out 0x1a,R24
	.dbline 61
;   PORTA=0XFF;
	out 0x1b,R24
	.dbline 62
;   DDRD=0X3F;
	ldi R24,63
	out 0x11,R24
	.dbline 63
;   DDRB=0XFF;
	ldi R24,255
	out 0x17,R24
	.dbline 64
;   PORTD=0XFF;
	out 0x12,R24
	.dbline 65
;   PORTB=0XFF;//端口初始化
	out 0x18,R24
	.dbline 66
;   TIMSK=0X21;//使能ICP捕捉中断;使能T/C0溢出中断
	ldi R24,33
	out 0x39,R24
	.dbline 67
;   TCCR0=0X02;
	ldi R24,2
	out 0x33,R24
	.dbline 68
;   TCCR1A=0X00;
	clr R2
	out 0x2f,R2
	.dbline 69
;   TCCR1B=0XC2;//8分频;捕捉最小单位1us
	ldi R24,194
	out 0x2e,R24
	.dbline 70
;   TCNT0=0;
	out 0x32,R2
	.dbline 71
;   ICR1=0;
	clr R3
	out 0x27,R3
	out 0x26,R2
	.dbline 72
;   TCNT1=0;
	out 0x2d,R3
	out 0x2c,R2
	.dbline -2
	.dbline 73
;   }
L16:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	.dbline -1
	.dbline 76
; //主程序:测量ICP引脚上信号的周期
; void main()
;   {
	.dbline 77
;   mcu_init();
	xcall _mcu_init
	.dbline 78
;   SREG|=0X80;
	bset 7
	.dbline 79
;   for(;;)
L18:
	.dbline 80
;       {
	.dbline 81
;          if((newcount&0xfff8)!=(oldcount&0xfff8))
	lds R24,_oldcount
	lds R25,_oldcount+1
	andi R24,248
	lds R30,_newcount
	lds R31,_newcount+1
	andi R30,248
	cp R30,R24
	cpc R31,R25
	breq L22
	.dbline 82
;                 {
	.dbline 83
;                 oldcount=newcount;
	lds R2,_newcount
	lds R3,_newcount+1
	sts _oldcount+1,R3
	sts _oldcount,R2
	.dbline 84
;                 }
L22:
	.dbline 85
	lds R16,_oldcount
	lds R17,_oldcount+1
	xcall _hextobcd
	.dbline 86
	xcall _display
	.dbline 87
	.dbline 79
	.dbline 79
	xjmp L18
X0:
	.dbline -2
L17:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Icp_timer1 _Icp_timer1 fV
	.even
_Icp_timer1::
	st -y,R2
	st -y,R3
	st -y,R24
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 91
;          hextobcd(oldcount);
;          display();
;       }
;   }
; //捕捉中断处理程序
; void Icp_timer1()
;   {
	.dbline 92
;   newcount=ICR1;
	in R2,0x26
	in R3,0x27
	sts _newcount+1,R3
	sts _newcount,R2
	.dbline 93
;   ICR1=0;
	clr R2
	clr R3
	out 0x27,R3
	out 0x26,R2
	.dbline 94
;   TCNT1=0;
	out 0x2d,R3
	out 0x2c,R2
	.dbline 95
;   TCCR1B=0XC2;
	ldi R24,194
	out 0x2e,R24
	.dbline -2
	.dbline 96
;   }
L24:
	ld R2,y+
	out 0x3f,R2
	ld R24,y+
	ld R3,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e Timer0 _Timer0 fV
	.even
_Timer0::
	st -y,R24
	st -y,R25
	in R24,0x3f
	st -y,R24
	.dbline -1
	.dbline 99
; //方波产生中断程序
; void Timer0()
;   {
	.dbline 100
;   i++;
	lds R24,_i
	subi R24,255    ; addi 1
	sts _i,R24
	.dbline 101
;   PORTA=i;//在PA口产生频率不同的方波
	out 0x1b,R24
	.dbline -2
	.dbline 103
;  
;   }
L25:
	ld R24,y+
	out 0x3f,R24
	ld R25,y+
	ld R24,y+
	.dbline 0 ; func end
	reti
	.dbend
	.area bss(ram, con, rel)
	.dbfile F:\李鹏飞\sl-avrad-m16\测脉宽\pulse_time.c
_newcount::
	.blkb 2
	.dbsym e newcount _newcount i
_oldcount::
	.blkb 2
	.dbsym e oldcount _oldcount i

⌨️ 快捷键说明

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