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

📄 模拟比较器.s

📁 AVR之ATMega16
💻 S
字号:
	.module _模拟比较器.c
	.area text(rom, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\精雅系列单片机实验开发板演示程序\模拟比较器/delay.h
	.dbfunc e DelayUS _DelayUS fV
;           time -> R16,R17
	.even
_DelayUS::
	.dbline -1
	.dbline 9
; //内部晶振 8M
; #include <ioM16v.h>
; #include <macros.h>
; #include"delay.h"
; 
; 
; 
; /*------宏定义------*/
; #define uchar	 unsigned char
	xjmp L3
L2:
	.dbline 11
	subi R16,1
	sbci R17,0
L3:
	.dbline 10
; #define uint	 unsigned int
	ldi R24,1
	ldi R25,0
	cp R24,R16
	cpc R25,R17
	brlo L2
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbsym r time 16 i
	.dbend
	.dbfunc e DelayMS _DelayMS fV
;              i -> R20,R21
;           time -> R16,R17
	.even
_DelayMS::
	xcall push_gset1
	.dbline -1
	.dbline 20
; #define LED_on   PORTA&=~BIT(PA0)
; #define LED_off  PORTA|=BIT(PA0)
; 
; //端口初始化
; void port_init(void)
; {
;  PORTA = 0xFF;//端口初始化
;  DDRA  = 0xFF;
;  PORTB = 0x00;
;  DDRB  = 0x00;
	xjmp L7
L6:
	.dbline 23
;  PORTC = 0x00;
;  DDRC  = 0x00;
;  PORTD = 0x00;
	.dbline 24
;  DDRD  = 0x00;
	ldi R20,1
	ldi R21,0
	xjmp L12
L9:
	.dbline 25
L10:
	.dbline 24
	subi R20,255  ; offset = 1
	sbci R21,255
L12:
	.dbline 24
	cpi R20,141
	ldi R30,0
	cpc R21,R30
	brlo L9
	.dbline 26
L7:
	.dbline 22
	movw R2,R16
	subi R16,1
	sbci R17,0
	tst R2
	brne L6
	tst R3
	brne L6
X0:
	.dbline -2
L5:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r time 16 i
	.dbend
	.dbfile C:\DOCUME~1\Administrator\桌面\精雅系列单片机实验开发板演示程序\模拟比较器\模拟比较器.c
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 16
	.dbline 17
	ldi R24,255
	out 0x1b,R24
	.dbline 18
	out 0x1a,R24
	.dbline 19
	clr R2
	out 0x18,R2
	.dbline 20
	out 0x17,R2
	.dbline 21
	out 0x15,R2
	.dbline 22
	out 0x14,R2
	.dbline 23
	out 0x12,R2
	.dbline 24
	out 0x11,R2
	.dbline -2
L13:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e comparator_init _comparator_init fV
	.even
_comparator_init::
	.dbline -1
	.dbline 30
; }
; 
; 
; //模拟比较器初始化
; void comparator_init(void)
; {
	.dbline 31
;  ACSR &= ~BIT(ACIE);//确保修改时不产生中断
	cbi 0x8,3
	.dbline 32
;  ACSR  = 0x48;//比较输出器变化触发中断
	ldi R24,72
	out 0x8,R24
	.dbline -2
L14:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 64
	jmp _ana_comp_isr
	.area text(rom, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\精雅系列单片机实验开发板演示程序\模拟比较器\模拟比较器.c
	.dbfunc e ana_comp_isr _ana_comp_isr fV
	.even
_ana_comp_isr::
	xcall push_lset
	.dbline -1
	.dbline 39
; }
; 
; 
; //模拟比较中断函数
; #pragma interrupt_handler ana_comp_isr:17
; void ana_comp_isr(void)
; {
	.dbline 40
;  DelayUS(10);
	ldi R16,10
	ldi R17,0
	xcall _DelayUS
	.dbline 42
; 
;     if (ACSR&(1<<ACO))  //检测ACO
	sbis 0x8,5
	rjmp L16
	.dbline 44
; 
;            LED_on;                 //如果LED亮
	cbi 0x1b,0
	xjmp L17
L16:
	.dbline 48
; 
;     else
; 
;            LED_off;               //否则 LED灭
	sbi 0x1b,0
L17:
	.dbline 50
; 
;    DelayMS(200);           //当电压差接近0V时,模拟比较器会产生临界抖动,故延时200mS令肉眼能看到    
	ldi R16,200
	ldi R17,0
	xcall _DelayMS
	.dbline -2
L15:
	xcall pop_lset
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 57
; 
; //通过判断ACO位来知道比较结果
; }
; 
; 
; void init_devices(void)
; {
	.dbline 58
;  CLI(); //禁止所有中断
	cli
	.dbline 59
;  MCUCR  = 0x00;//INT0、INT1中断触发方式
	clr R2
	out 0x35,R2
	.dbline 60
;  MCUCSR = 0x80;//禁止JTAG
	ldi R24,128
	out 0x34,R24
	.dbline 61
;  GICR   = 0x00;//外部中断使能
	out 0x3b,R2
	.dbline 62
;  port_init();
	xcall _port_init
	.dbline 63
;  comparator_init();
	xcall _comparator_init
	.dbline 64
;  SEI();//开全局中断
	sei
	.dbline -2
L18:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	.dbline -1
	.dbline 68
; }
; //主函数
; void main(void)
; {
	.dbline 69
;  init_devices();
	xcall _init_devices
	xjmp L21
L20:
	.dbline 72
	.dbline 73
	nop
	.dbline 74
L21:
	.dbline 71
	xjmp L20
X1:
	.dbline -2
L19:
	.dbline 0 ; func end
	ret
	.dbend

⌨️ 快捷键说明

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