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

📄 main.s

📁 用的avr icc 开发的atmega16的超声波测距仪模型。
💻 S
字号:
	.module main.c
	.area data(ram, con, rel)
_data::
	.blkb 2
	.area idata
	.byte 0,0
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 0,0
	.area data(ram, con, rel)
	.dbfile D:\NEW\ECHO/main.h
	.dbsym e data _data A[4:4]c
_ASCII_T::
	.blkb 2
	.area idata
	.byte 0,0
	.area data(ram, con, rel)
	.dbfile D:\NEW\ECHO/main.h
	.blkb 2
	.area idata
	.byte 0,0
	.area data(ram, con, rel)
	.dbfile D:\NEW\ECHO/main.h
	.dbsym e ASCII_T _ASCII_T A[4:4]c
	.area text(rom, con, rel)
	.dbfile D:\NEW\ECHO/main.h
	.dbfile D:\NEW\ECHO\main.c
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 7
; #define MAIN_C
; #include "includes.h"
; //ICC-AVR application builder : 2007-1-22 9:46:41
; // Target : M16
; // Crystal: 4.0000Mhz
; void port_init(void)
; {
	.dbline 8
;  PORTA = 0xFF;
	ldi R24,255
	out 0x1b,R24
	.dbline 9
;  DDRA  = 0x00;
	clr R2
	out 0x1a,R2
	.dbline 10
;  PORTB = 0xfe;// SEND ECHO
	ldi R24,254
	out 0x18,R24
	.dbline 11
;  DDRB  = 0x01;
	ldi R24,1
	out 0x17,R24
	.dbline 12
;  PORTC = 0xff; //m103 output only
	ldi R24,255
	out 0x15,R24
	.dbline 13
;  DDRC  = 0x00;
	out 0x14,R2
	.dbline 14
;  PORTD = 0xFF;
	out 0x12,R24
	.dbline 15
;  DDRD  = 0x00;
	out 0x11,R2
	.dbline -2
	.dbline 16
; }
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 20
; 
; //call this routine to initialise all peripherals
; void init_devices(void)
; {
	.dbline 22
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 23
;  port_init();
	xcall _port_init
	.dbline 24
;  Init_LCD();
	xcall _Init_LCD
	.dbline 25
;  timer1_init();
	xcall _timer1_init
	.dbline 26
;  MCUCR = 0x00;
	clr R2
	out 0x35,R2
	.dbline 27
;  GICR  = 0x00;
	out 0x3b,R2
	.dbline 28
;  TIMSK = 0x24; //OVR(0x20)+ICP(0x04) interrupt sources
	ldi R24,36
	out 0x39,R24
	.dbline 29
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
	.dbline 31
;  //all peripherals are now initialised
; }
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e display_temprature _display_temprature fV
	.even
_display_temprature::
	.dbline -1
	.dbline 34
; 
; void display_temprature(void)
;   {
	.dbline 35
;    temprature= readTempDS18B20();
	xcall _readTempDS18B20
	sts _temprature+1,R17
	sts _temprature,R16
	.dbline 37
; 
;    temprature_flag=(temprature>>8)&0xf8;//h8bit(5bit)
	movw R24,R16
	mov R24,R25
	clr R25
	andi R24,248
	andi R25,0
	sts _temprature_flag,R24
	.dbline 39
;    
;     if(temprature_flag==0)              //signed temprature 
	tst R24
	brne L4
	.dbline 40
; 	 {
	.dbline 41
; 	    temprature/=8;
	movw R2,R16
	lsr R3
	ror R2
	lsr R3
	ror R2
	lsr R3
	ror R2
	sts _temprature+1,R3
	sts _temprature,R2
	.dbline 42
; 		temprature*=5;
	movw R18,R2
	ldi R16,5
	ldi R17,0
	xcall empy16s
	sts _temprature+1,R17
	sts _temprature,R16
	.dbline 43
; 	    LCD_Cursor(1,8);
	ldi R18,8
	ldi R16,1
	xcall _LCD_Cursor
	.dbline 44
; 	    LCD_DisplayCharacter('+');
	ldi R16,43
	xcall _LCD_DisplayCharacter
	.dbline 45
; 		speed=3314+temprature*6;  //set speed for echo
	lds R18,_temprature
	lds R19,_temprature+1
	ldi R16,6
	ldi R17,0
	xcall empy16s
	movw R24,R16
	subi R24,14  ; offset = 3314
	sbci R25,243
	sts _speed+1,R25
	sts _speed,R24
	.dbline 46
; 	 }
L4:
	.dbline 48
; 	 
; 	 if(temprature_flag!=0)
	lds R2,_temprature_flag
	tst R2
	breq L6
	.dbline 49
; 	 { 
	.dbline 50
; 	   temprature=~temprature+1;
	lds R24,_temprature
	lds R25,_temprature+1
	com R24
	com R25
	adiw R24,1
	sts _temprature+1,R25
	sts _temprature,R24
	.dbline 51
; 	   temprature&=~0xf800;
	andi R25,7
	sts _temprature+1,R25
	sts _temprature,R24
	.dbline 52
;        temprature/=8;
	movw R2,R24
	lsr R3
	ror R2
	lsr R3
	ror R2
	lsr R3
	ror R2
	sts _temprature+1,R3
	sts _temprature,R2
	.dbline 53
; 	   temprature*=5;
	movw R18,R2
	ldi R16,5
	ldi R17,0
	xcall empy16s
	sts _temprature+1,R17
	sts _temprature,R16
	.dbline 54
;        LCD_Cursor(1,8);
	ldi R18,8
	ldi R16,1
	xcall _LCD_Cursor
	.dbline 55
; 	   LCD_DisplayCharacter('-');
	ldi R16,45
	xcall _LCD_DisplayCharacter
	.dbline 56
; 	   speed=3314-temprature*6;  //set speed for echo	 
	lds R18,_temprature
	lds R19,_temprature+1
	ldi R16,6
	ldi R17,0
	xcall empy16s
	ldi R24,3314
	ldi R25,12
	sub R24,R16
	sbc R25,R17
	sts _speed+1,R25
	sts _speed,R24
	.dbline 57
;      }
L6:
	.dbline 61
; 	 
; 	//temprature=speed;//testing!!!!!!!!!!!!!!!!!!!!!!!!
; 	 
; 	 ASCII_T[0]='0'+temprature/1000;
	ldi R18,1000
	ldi R19,3
	lds R16,_temprature
	lds R17,_temprature+1
	xcall div16u
	movw R24,R16
	adiw R24,48
	sts _ASCII_T,R24
	.dbline 62
; 	 temprature%=1000;
	ldi R18,1000
	ldi R19,3
	lds R16,_temprature
	lds R17,_temprature+1
	xcall mod16u
	sts _temprature+1,R17
	sts _temprature,R16
	.dbline 63
; 	  ASCII_T[1]='0'+temprature/100;
	ldi R18,100
	ldi R19,0
	xcall div16u
	movw R24,R16
	adiw R24,48
	sts _ASCII_T+1,R24
	.dbline 64
; 	 temprature%=100;
	ldi R18,100
	ldi R19,0
	lds R16,_temprature
	lds R17,_temprature+1
	xcall mod16u
	sts _temprature+1,R17
	sts _temprature,R16
	.dbline 65
; 	  ASCII_T[2]='0'+temprature/10;
	ldi R18,10
	ldi R19,0
	xcall div16u
	movw R24,R16
	adiw R24,48
	sts _ASCII_T+2,R24
	.dbline 66
; 	 temprature%=10;
	ldi R18,10
	ldi R19,0
	lds R16,_temprature
	lds R17,_temprature+1
	xcall mod16u
	sts _temprature+1,R17
	sts _temprature,R16
	.dbline 67
; 	  ASCII_T[3]='0'+temprature;
	movw R24,R16
	adiw R24,48
	sts _ASCII_T+3,R24
	.dbline 68
; 	 LCD_Cursor(1,9);
	ldi R18,9
	ldi R16,1
	xcall _LCD_Cursor
	.dbline 69
; 	 LCD_DisplayCharacter(ASCII_T[0]);	//100BIT
	lds R16,_ASCII_T
	xcall _LCD_DisplayCharacter
	.dbline 70
; 	 LCD_Cursor(1,10);
	ldi R18,10
	ldi R16,1
	xcall _LCD_Cursor
	.dbline 71
; 	 LCD_DisplayCharacter(ASCII_T[1]);	//10BIT
	lds R16,_ASCII_T+1
	xcall _LCD_DisplayCharacter
	.dbline 72
; 	 LCD_Cursor(1,11);
	ldi R18,11
	ldi R16,1
	xcall _LCD_Cursor
	.dbline 73
; 	 LCD_DisplayCharacter(ASCII_T[2]);	//1BIT
	lds R16,_ASCII_T+2
	xcall _LCD_DisplayCharacter
	.dbline 74
; 	 LCD_Cursor(1,12);
	ldi R18,12
	ldi R16,1
	xcall _LCD_Cursor
	.dbline 75
; 	 LCD_DisplayCharacter('.');// . BIT	
	ldi R16,46
	xcall _LCD_DisplayCharacter
	.dbline 76
; 	 LCD_Cursor(1,13);
	ldi R18,13
	ldi R16,1
	xcall _LCD_Cursor
	.dbline 77
; 	 LCD_DisplayCharacter(ASCII_T[0]);//0.1BIT			 
	lds R16,_ASCII_T
	xcall _LCD_DisplayCharacter
	.dbline 78
;      LCD_Cursor(1,14);
	ldi R18,14
	ldi R16,1
	xcall _LCD_Cursor
	.dbline 79
; 	 LCD_DisplayCharacter('`');	//UNIT
	ldi R16,96
	xcall _LCD_DisplayCharacter
	.dbline 80
; 	 LCD_DisplayCharacter('C');	//UNIT
	ldi R16,67
	.dbline -2
	.dbline 81
;   }
L3:
	.dbline 0 ; func end
	xjmp _LCD_DisplayCharacter
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	sbiw R28,2
	.dbline -1
	.dbline 84
; 
; void main(void)
;  {  //initial and the picture of starting work 
	.dbline 85
;     init_devices();
	xcall _init_devices
	.dbline 86
;     LCD_DisplayString(1,2,"NOW");
	ldi R24,<L14
	ldi R25,>L14
	std y+1,R25
	std y+0,R24
	ldi R18,2
	ldi R16,1
	xcall _LCD_DisplayString
	.dbline 87
; 	LCD_DisplayString(2,1,"  ULTRASONIC ");
	ldi R24,<L15
	ldi R25,>L15
	std y+1,R25
	std y+0,R24
	ldi R18,1
	ldi R16,2
	xcall _LCD_DisplayString
	.dbline 88
; 	display_temprature();
	xcall _display_temprature
	.dbline 89
;     delay_nms(3000);
	ldi R16,3000
	ldi R17,11
	xcall _delay_nms
	.dbline 90
; 	ClearLine(2);
	ldi R16,2
	xcall _ClearLine
	xjmp L17
L16:
	.dbline 92
	.dbline 93
	xcall _display_temprature
	.dbline 95
	ldi R24,<L19
	ldi R25,>L19
	std y+1,R25
	std y+0,R24
	ldi R18,1
	ldi R16,1
	xcall _LCD_DisplayString
	.dbline 96
	clr R2
	out 0x39,R2
	.dbline 97
	ldi R16,16
	ldi R17,0
	xcall _pwm_40KHz
	.dbline 98
	xcall _timer1_start
	.dbline 99
	ldi R16,8
	ldi R17,0
	xcall _pwm_20KHz
	.dbline 100
	ldi R16,5
	ldi R17,0
	xcall _delay_nms
	.dbline 101
	ldi R24,36
	out 0x39,R24
	.dbline 102
	ldi R16,200
	ldi R17,0
	xcall _delay_nms
	.dbline 103
L17:
	.dbline 91
	xjmp L16
X0:
	.dbline -2
	.dbline 104
;   while(1)
;    {    
; 	    display_temprature();
; 		
; 	    LCD_DisplayString(1,1,"40KHz");
; 		TIMSK = 0x00; //delay for voiding  self noise 
; 		pwm_40KHz(16);
;         timer1_start();
; 		pwm_20KHz(8);
; 		delay_nms(5);//lenth shoud far more than 1m for self noise
; 		TIMSK = 0x24; //OVR(0x04)+ICP(0x20) interrupt sources
; 		delay_nms(200);// one frush per second
;   }
; }  
L13:
	adiw R28,2
	.dbline 0 ; func end
	ret
	.dbend
	.area bss(ram, con, rel)
	.dbfile D:\NEW\ECHO\main.c
_speed::
	.blkb 2
	.dbfile D:\NEW\ECHO/main.h
	.dbsym e speed _speed i
_temprature_flag::
	.blkb 1
	.dbsym e temprature_flag _temprature_flag c
_temprature::
	.blkb 2
	.dbsym e temprature _temprature i
	.area data(ram, con, rel)
	.dbfile D:\NEW\ECHO/main.h
L19:
	.blkb 6
	.area idata
	.byte 52,48,'K,'H,'z,0
	.area data(ram, con, rel)
	.dbfile D:\NEW\ECHO/main.h
L15:
	.blkb 14
	.area idata
	.byte 32,32,'U,'L,'T,'R,'A,'S,'O,'N,'I,'C,32,0
	.area data(ram, con, rel)
	.dbfile D:\NEW\ECHO/main.h
L14:
	.blkb 4
	.area idata
	.byte 'N,'O,'W,0
	.area data(ram, con, rel)
	.dbfile D:\NEW\ECHO/main.h

⌨️ 快捷键说明

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