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

📄 adc.s

📁 AVR单片机ATMEGA内部自带AD转换器实例
💻 S
📖 第 1 页 / 共 2 页
字号:
	.dbline 236
; 	EICRA = 0xaa;		//fall edge trigger
	ldi R24,170
	sts 106,R24
	.dbline 237
; 	EICRB = 0x00;		//no influence
	clr R2
	out 0x3a,R2
	.dbline 238
; 	EIMSK = 0x0f;
	ldi R24,15
	out 0x39,R24
	.dbline 240
; 
; 	SEI();
	sei
	.dbline -2
	.dbline 242
; 
; }
L40:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e UART_initialize _UART_initialize fV
	.even
_UART_initialize::
	.dbline -1
	.dbline 244
; void UART_initialize(void)
; {
	.dbline 245
; 	CLI();
	cli
	.dbline 247
; 	
; 	UBRR0H = 0x00;
	clr R2
	sts 144,R2
	.dbline 248
; 	UBRR0L = 0x67;		//波特率9600bps
	ldi R24,103
	out 0x9,R24
	.dbline 249
; 	UCSR0A = 0x00;
	out 0xb,R2
	.dbline 250
; 	UCSR0B = 0x98;		//11011000接收与发送使能
	ldi R24,152
	out 0xa,R24
	.dbline 251
; 	UCSR0C = 0x26;		//00100110帧格式: 8bits,1stop bit,P 校验
	ldi R24,38
	sts 149,R24
	.dbline 253
; 
; 	SEI();
	sei
	.dbline -2
	.dbline 254
; }
L41:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Delay _Delay fV
;              i -> R16,R17
	.even
_Delay::
	.dbline -1
	.dbline 256
; void Delay(void)
; {
	.dbline 259
; 	unsigned int i;
; 
; 	for ( i = 0; i < 6000; i++ )
	clr R16
	clr R17
	xjmp L46
L43:
	.dbline 260
	.dbline 261
	nop
	.dbline 262
L44:
	.dbline 259
	subi R16,255  ; offset = 1
	sbci R17,255
L46:
	.dbline 259
	cpi R16,112
	ldi R30,23
	cpc R17,R30
	brlo L43
	.dbline -2
	.dbline 263
; 	{
; 		NOP();
; 	}
; }
L42:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 i
	.dbend
	.dbfunc e External_INT_0 _External_INT_0 fV
	.even
_External_INT_0::
	st -y,R24
	in R24,0x3f
	st -y,R24
	.dbline -1
	.dbline 268
; 
; 
; 
; void External_INT_0(void)
; {
	.dbline 270
; 	
; 	ADCSR |= ADC_start;
	sbi 0x6,6
	.dbline 272
; 
; 	DDRB |=0xF0;		//放在这个位置是错误的,中断回到入口之处
	in R24,0x17
	ori R24,240
	out 0x17,R24
	.dbline 274
; 
; 	Display_flag = 1;
	ldi R24,1
	sts _Display_flag,R24
	.dbline -2
	.dbline 278
; 	
; 	/*UCSR0B |= 0x40;
; 	UCSR0B &= ~(0x80);*/
; }
L47:
	ld R24,y+
	out 0x3f,R24
	ld R24,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e ADC_INT _ADC_INT fV
	.even
_ADC_INT::
	st -y,R2
	st -y,R3
	st -y,R16
	st -y,R17
	st -y,R30
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 281
; 
; void ADC_INT(void)
; {
	.dbline 282
; 	AD_sample_value = ADC; 
	in R2,0x4
	in R3,0x5
	sts _AD_sample_value+1,R3
	sts _AD_sample_value,R2
	.dbline 284
; 	//PORTB = Blue_LED_on;
; 	switch (Type_flag)
	lds R16,_Type_flag
	clr R17
	cpi R16,1
	ldi R30,0
	cpc R17,R30
	breq L52
	cpi R16,2
	ldi R30,0
	cpc R17,R30
	breq L53
	cpi R16,3
	ldi R30,0
	cpc R17,R30
	breq L54
	xjmp L49
X2:
	.dbline 285
; 	{
L52:
	.dbline 287
; 		case 1:				
; 		{
	.dbline 288
; 			channel_1_flag = 0; 
	clr R2
	sts _channel_1_flag,R2
	.dbline 290
; 		
; 		}break;
	.dbline 290
	xjmp L50
L53:
	.dbline 293
; 
; 		case 2:				
; 		{
	.dbline 294
; 			channel_2_flag = 0;
	clr R2
	sts _channel_2_flag,R2
	.dbline 296
; 
; 		}break;
	.dbline 296
	xjmp L50
L54:
	.dbline 299
; 
; 		case 3:				
; 		{
	.dbline 300
; 			channel_3_flag = 0;
	clr R2
	sts _channel_3_flag,R2
	.dbline 302
; 		
; 		}break;
	.dbline 302
	xjmp L50
L49:
	.dbline 305
	.dbline 306
	clr R2
	sts _channel_0_flag,R2
	.dbline 308
	.dbline 308
L50:
	.dbline -2
	.dbline 310
; 
; 		default:
; 		{
; 			channel_0_flag = 0;
; 			
; 		}break;
; 	}
; }
L48:
	ld R2,y+
	out 0x3f,R2
	ld R30,y+
	ld R17,y+
	ld R16,y+
	ld R3,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e External_INT_1 _External_INT_1 fV
	.even
_External_INT_1::
	st -y,R2
	st -y,R24
	st -y,R25
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 313
; 
; void External_INT_1(void)
; {
	.dbline 314
; 	if (Type_flag < 3 )
	lds R24,_Type_flag
	cpi R24,3
	brsh L56
	.dbline 315
; 	{
	.dbline 316
; 		Type_flag += 1;
	subi R24,255    ; addi 1
	sts _Type_flag,R24
	.dbline 317
; 	}
	xjmp L57
L56:
	.dbline 319
; 	else
; 	{
	.dbline 320
; 		Type_flag = 0;
	clr R2
	sts _Type_flag,R2
	.dbline 321
; 	}
L57:
	.dbline 323
; 
; 	ADMUX = (ADMUX&0xf8)|Type_flag;	//0x41;  //
	lds R2,_Type_flag
	in R24,0x7
	andi R24,248
	or R24,R2
	out 0x7,R24
	.dbline 324
; 	Display_flag = 0;
	clr R2
	sts _Display_flag,R2
	.dbline 325
; 	DDRB &=0x1F;
	in R24,0x17
	andi R24,31
	out 0x17,R24
	.dbline -2
	.dbline 326
; }
L55:
	ld R2,y+
	out 0x3f,R2
	ld R25,y+
	ld R24,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e External_INT_2 _External_INT_2 fV
	.even
_External_INT_2::
	.dbline -1
	.dbline 328
; void External_INT_2(void)
; {
	.dbline -2
	.dbline 333
;  	
; 	
; 
; 	
; }
L58:
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e LED_Display _LED_Display fV
;           Data -> R22,R23
;    Channel_num -> R20
	.even
_LED_Display::
	xcall push_gset2
	movw R22,R18
	mov R20,R16
	.dbline -1
	.dbline 335
; void LED_Display(unsigned char Channel_num,unsigned int Data)
; {
	.dbline 337
; 	
; 	DATA_to_NUM(Data);
	movw R16,R22
	xcall _DATA_to_NUM
	.dbline 339
; 	
; 	PORTA = LED_table[number_baifen] ;
	ldi R24,<_LED_table
	ldi R25,>_LED_table
	lds R30,_number_baifen
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	out 0x1b,R2
	.dbline 340
; 	PORTB = (PORTB|0xf0)&0x7F;
	in R24,0x18
	ori R24,240
	andi R24,127
	out 0x18,R24
	.dbline 341
; 	Delay();
	xcall _Delay
	.dbline 343
; 
; 	PORTA = LED_table[number_shifen];
	ldi R24,<_LED_table
	ldi R25,>_LED_table
	lds R30,_number_shifen
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	out 0x1b,R2
	.dbline 344
; 	PORTB = (PORTB|0xf0)&0xBF;
	in R24,0x18
	ori R24,240
	andi R24,191
	out 0x18,R24
	.dbline 345
; 	Delay();
	xcall _Delay
	.dbline 347
; 	
; 	PORTA = LED_table[number_ge_dot] + 0x80;
	ldi R24,<_LED_table
	ldi R25,>_LED_table
	lds R30,_number_ge_dot
	clr R31
	add R30,R24
	adc R31,R25
	ldd R24,z+0
	subi R24,128    ; addi 128
	out 0x1b,R24
	.dbline 348
; 	PORTB = (PORTB|0xf0)&0xDF;
	in R24,0x18
	ori R24,240
	andi R24,223
	out 0x18,R24
	.dbline 349
; 	Delay();
	xcall _Delay
	.dbline 351
; 
; 	PORTA = LED_table[Channel_num];
	ldi R24,<_LED_table
	ldi R25,>_LED_table
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	out 0x1b,R2
	.dbline 352
; 	PORTB =	(PORTB|0xf0)&0xEF;
	in R24,0x18
	ori R24,240
	andi R24,239
	out 0x18,R24
	.dbline 353
; 	Delay();
	xcall _Delay
	.dbline -2
	.dbline 354
; }
L59:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r Data 22 i
	.dbsym r Channel_num 20 c
	.dbend
	.dbfunc e DATA_to_NUM _DATA_to_NUM fV
;           temp -> R20,R21
;           data -> R20,R21
	.even
_DATA_to_NUM::
	xcall push_gset2
	movw R20,R16
	sbiw R28,4
	.dbline -1
	.dbline 357
; 
; void DATA_to_NUM(unsigned int data)
; {
	.dbline 360
; 	unsigned int temp;
; 
; 	temp = (unsigned int)(((float)data)*500/1024);
	ldi R16,<L63
	ldi R17,>L63
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	ldi R16,<L64
	ldi R17,>L64
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R16,R20
	lsr R17
	ror R16
	xcall int2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall empy32fs
	movw R16,R20
	andi R16,1
	andi R17,0
	xcall int2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall add32fs
	xcall empy32fs
	ldi R16,<L65
	ldi R17,>L65
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall div32f
	movw R30,R28
	std z+0,R16
	std z+1,R17
	std z+2,R18
	std z+3,R19
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L66
	ldi R17,>L66
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall cmp32f
	brlt L61
	movw R30,R28
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L66
	ldi R17,>L66
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall sub32f
	xcall fp2int
	movw R22,R16
	subi R22,0  ; offset = 32768
	sbci R23,128
	xjmp L62
L61:
	movw R30,R28
	ldd R16,z+0
	ldd R17,z+1
	ldd R18,z+2
	ldd R19,z+3
	xcall fp2int
	movw R22,R16
L62:
	movw R20,R22
	.dbline 362
; 
; 	number_ge_dot = temp/100;
	ldi R18,100
	ldi R19,0
	movw R16,R20
	xcall div16u
	sts _number_ge_dot,R16
	.dbline 363
; 	number_shifen = (temp%100)/10;
	ldi R18,100
	ldi R19,0
	movw R16,R20
	xcall mod16u
	ldi R18,10
	ldi R19,0
	xcall div16u
	sts _number_shifen,R16
	.dbline 364
; 	number_baifen = (temp%100)%10;
	ldi R18,100
	ldi R19,0
	movw R16,R20
	xcall mod16u
	ldi R18,10
	ldi R19,0
	xcall mod16u
	sts _number_baifen,R16
	.dbline -2
	.dbline 365
; }
L60:
	adiw R28,4
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r temp 20 i
	.dbsym r data 20 i
	.dbend
	.area bss(ram, con, rel)
	.dbfile G:\猛\avr实践\AD\adc.c
_m::
	.blkb 1
	.dbsym e m _m c
_Display_value::
	.blkb 1
	.dbsym e Display_value _Display_value c
_Display_type::
	.blkb 1
	.dbsym e Display_type _Display_type c
_number_ge_dot::
	.blkb 1
	.dbsym e number_ge_dot _number_ge_dot c
_number_shifen::
	.blkb 1
	.dbsym e number_shifen _number_shifen c
_number_baifen::
	.blkb 1
	.dbsym e number_baifen _number_baifen c
_AD_sample_value::
	.blkb 2
	.dbsym e AD_sample_value _AD_sample_value i
	.area lit(rom, con, rel)
L66:
	.word 0x0,0x4700
L65:
	.word 0x0,0x4480
L64:
	.word 0x0,0x4000
L63:
	.word 0x0,0x43fa

⌨️ 快捷键说明

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