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

📄 uart.s

📁 AVR单片机ATMEGA128实习之—串口通信(附带Proteus仿真例子)
💻 S
📖 第 1 页 / 共 2 页
字号:
	ldi R24,103
	out 0x9,R24
	.dbline 190
; 	UCSR0A = 0x00;
	out 0xb,R2
	.dbline 191
; 	UCSR0B = 0x98;		//11011000接收与发送使能
	ldi R24,152
	out 0xa,R24
	.dbline 192
; 	UCSR0C = 0x26;		//00100110帧格式: 8bits,1stop bit,P 校验
	ldi R24,38
	sts 149,R24
	.dbline 194
; 
; 	SEI();
	sei
	.dbline -2
	.dbline 195
; }
L27:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Delay _Delay fV
;              i -> R16,R17
	.even
_Delay::
	.dbline -1
	.dbline 197
; void Delay(void)
; {
	.dbline 200
; 	unsigned int i;
; 
; 	for ( i = 0; i < 6000; i++ )
	clr R16
	clr R17
	xjmp L32
L29:
	.dbline 201
	.dbline 202
	nop
	.dbline 203
L30:
	.dbline 200
	subi R16,255  ; offset = 1
	sbci R17,255
L32:
	.dbline 200
	cpi R16,112
	ldi R30,23
	cpc R17,R30
	brlo L29
	.dbline -2
	.dbline 204
; 	{
; 		NOP();
; 	}
; }
L28:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 i
	.dbend
	.dbfunc e UART0_TX_INT _UART0_TX_INT fV
	.even
_UART0_TX_INT::
	st -y,R2
	st -y,R24
	st -y,R25
	st -y,R30
	st -y,R31
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 207
; 
; void UART0_TX_INT(void)
; {
	.dbline 208
; 	UART0_TX_flag = 0;
	clr R2
	sts _UART0_TX_flag,R2
	.dbline 210
; 	
; 	if (Tx_counter<10)
	lds R24,_Tx_counter
	cpi R24,10
	brsh L34
	.dbline 211
; 	{
	.dbline 212
; 		Tx_counter += 1;
	subi R24,255    ; addi 1
	sts _Tx_counter,R24
	.dbline 213
; 	}
	xjmp L35
L34:
	.dbline 215
; 	else
; 	{
	.dbline 216
; 		Tx_counter = 1;
	ldi R24,1
	sts _Tx_counter,R24
	.dbline 217
; 	}
L35:
	.dbline 219
; 	
; 	Tx_data = Tx_data_buf[Tx_counter-1];
	ldi R24,<_Tx_data_buf-1
	ldi R25,>_Tx_data_buf-1
	lds R30,_Tx_counter
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	sts _Tx_data,R2
	.dbline 221
; 	
; 	UDR0 = Tx_data;		//data to transmit
	out 0xc,R2
	.dbline 222
; 	UCSR0B &=0xbf ;		//1011 1111关闭发送中断
	in R24,0xa
	andi R24,191
	out 0xa,R24
L37:
	.dbline 225
	.dbline 226
L38:
	.dbline 224
; 
; 	while ( !( UCSR0A & (1<<UDRE0)) )	//等待发送缓冲区空
	sbis 0xb,5
	rjmp L37
	.dbline 228
; 	{
; 	}
; 	
; 	UCSR0B |= 0x80;	
	sbi 0xa,7
	.dbline -2
	.dbline 229
; }
L33:
	ld R2,y+
	out 0x3f,R2
	ld R31,y+
	ld R30,y+
	ld R25,y+
	ld R24,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e UART0_RX_INT _UART0_RX_INT fV
	.even
_UART0_RX_INT::
	st -y,R2
	st -y,R24
	st -y,R25
	st -y,R30
	st -y,R31
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 232
; 
; void UART0_RX_INT(void)
; {
	.dbline 233
; 	Rx_data = UDR0;
	in R2,0xc
	sts _Rx_data,R2
	.dbline 234
; 	UART0_RX_flag = 0;
	clr R2
	sts _UART0_RX_flag,R2
	.dbline 236
; 
; 	if (Rx_counter < 10)
	lds R24,_Rx_counter
	cpi R24,10
	brsh L41
	.dbline 237
; 	{
	.dbline 238
; 		Rx_counter += 1;
	subi R24,255    ; addi 1
	sts _Rx_counter,R24
	.dbline 239
; 	}
	xjmp L42
L41:
	.dbline 241
; 	else
; 	{
	.dbline 242
; 		Rx_counter = 1;
	ldi R24,1
	sts _Rx_counter,R24
	.dbline 243
; 	}
L42:
	.dbline 245
; 
; 	Rx_data_buf[Rx_counter - 1] = Rx_data; 
	ldi R24,<_Rx_data_buf-1
	ldi R25,>_Rx_data_buf-1
	lds R30,_Rx_counter
	clr R31
	add R30,R24
	adc R31,R25
	lds R2,_Rx_data
	std z+0,R2
	.dbline 246
; 	PORTB = Green_LED_on;
	cbi 0x18,1
	.dbline -2
	.dbline 248
; 
; }
L40:
	ld R2,y+
	out 0x3f,R2
	ld R31,y+
	ld R30,y+
	ld R25,y+
	ld R24,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e External_INT_0 _External_INT_0 fV
	.even
_External_INT_0::
	st -y,R0
	in R0,0x3f
	st -y,R0
	.dbline -1
	.dbline 251
; 
; void External_INT_0(void)
; {
	.dbline 252
; 	UCSR0B |= 0x40;
	sbi 0xa,6
	.dbline 253
; 	UCSR0B &= ~(0x80);
	cbi 0xa,7
	.dbline -2
	.dbline 254
; }
L44:
	ld R0,y+
	out 0x3f,R0
	ld R0,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 257
; 
; void External_INT_1(void)
; {
	.dbline 258
; 	if (Type_flag < 4 )
	lds R24,_Type_flag
	cpi R24,4
	brsh L46
	.dbline 259
; 	{
	.dbline 260
; 		Type_flag += 1;
	subi R24,255    ; addi 1
	sts _Type_flag,R24
	.dbline 261
; 	}
	xjmp L47
L46:
	.dbline 263
	.dbline 264
	clr R2
	sts _Type_flag,R2
	.dbline 265
L47:
	.dbline -2
	.dbline 266
; 	else
; 	{
; 		Type_flag = 0;
; 	}
; }
L45:
	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::
	st -y,R2
	st -y,R24
	st -y,R25
	st -y,R30
	st -y,R31
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 268
; void External_INT_2(void)
; {
	.dbline 270
;  	
; 	if(m < 12)
	lds R24,_m
	cpi R24,12
	brsh L49
	.dbline 271
; 	{
	.dbline 272
; 		m += 1;
	subi R24,255    ; addi 1
	sts _m,R24
	.dbline 273
; 	}
	xjmp L50
L49:
	.dbline 275
; 	else
; 	{
	.dbline 276
; 		m = 1;
	ldi R24,1
	sts _m,R24
	.dbline 277
; 	}
L50:
	.dbline 279
; 
; 	Display_type = 0x0f;
	ldi R24,15
	sts _Display_type,R24
	.dbline 280
; 	Display_value = Rx_data_buf[m-1];
	ldi R24,<_Rx_data_buf-1
	ldi R25,>_Rx_data_buf-1
	lds R30,_m
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	sts _Display_value,R2
	.dbline -2
	.dbline 283
; 
; 	
; }
L48:
	ld R2,y+
	out 0x3f,R2
	ld R31,y+
	ld R30,y+
	ld R25,y+
	ld R24,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e LED_Display _LED_Display fV
;           Data -> R22
;           Type -> R20
	.even
_LED_Display::
	xcall push_gset2
	mov R22,R18
	mov R20,R16
	.dbline -1
	.dbline 285
; void LED_Display(unsigned char Type,unsigned char Data)
; {
	.dbline 287
; 	
; 	DATA_to_NUM(Data);
	mov R16,R22
	xcall _DATA_to_NUM
	.dbline 289
; 	
; 	PORTA = LED_table[number_ge];
	ldi R24,<_LED_table
	ldi R25,>_LED_table
	lds R30,_number_ge
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	out 0x1b,R2
	.dbline 290
; 	PORTB = (PORTB|0xf0)&0x7F;
	in R24,0x18
	ori R24,240
	andi R24,127
	out 0x18,R24
	.dbline 291
; 	Delay();
	xcall _Delay
	.dbline 293
; 
; 	PORTA = LED_table[number_shi];
	ldi R24,<_LED_table
	ldi R25,>_LED_table
	lds R30,_number_shi
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	out 0x1b,R2
	.dbline 294
; 	PORTB = (PORTB|0xf0)&0xBF;
	in R24,0x18
	ori R24,240
	andi R24,191
	out 0x18,R24
	.dbline 295
; 	Delay();
	xcall _Delay
	.dbline 297
; 	
; 	PORTA = LED_table[number_bai];
	ldi R24,<_LED_table
	ldi R25,>_LED_table
	lds R30,_number_bai
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	out 0x1b,R2
	.dbline 298
; 	PORTB = (PORTB|0xf0)&0xDF;
	in R24,0x18
	ori R24,240
	andi R24,223
	out 0x18,R24
	.dbline 299
; 	Delay();
	xcall _Delay
	.dbline 301
; 
; 	PORTA = LED_table[Type];
	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 302
; 	PORTB =	(PORTB|0xf0)&0xEF;
	in R24,0x18
	ori R24,240
	andi R24,239
	out 0x18,R24
	.dbline 303
; 	Delay();
	xcall _Delay
	.dbline -2
	.dbline 304
; }
L52:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r Data 22 c
	.dbsym r Type 20 c
	.dbend
	.dbfunc e DATA_to_NUM _DATA_to_NUM fV
;           data -> R20
	.even
_DATA_to_NUM::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 307
; 
; void DATA_to_NUM(unsigned char data)
; {
	.dbline 308
; 	number_bai = data/100;
	ldi R17,100
	mov R16,R20
	xcall div8u
	sts _number_bai,R16
	.dbline 309
; 	number_shi = (data%100)/10;
	ldi R17,100
	mov R16,R20
	xcall mod8u
	ldi R17,10
	xcall div8u
	sts _number_shi,R16
	.dbline 310
; 	number_ge  = (data%100)%10;
	ldi R17,100
	mov R16,R20
	xcall mod8u
	ldi R17,10
	xcall mod8u
	sts _number_ge,R16
	.dbline -2
	.dbline 311
; }
L53:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r data 20 c
	.dbend
	.area bss(ram, con, rel)
	.dbfile G:\猛\avr实践\UART\UART.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::
	.blkb 1
	.dbsym e number_ge _number_ge c
_number_shi::
	.blkb 1
	.dbsym e number_shi _number_shi c
_number_bai::
	.blkb 1
	.dbsym e number_bai _number_bai c
_Rx_data::
	.blkb 1
	.dbsym e Rx_data _Rx_data c
_Rx_data_buf::
	.blkb 12
	.dbsym e Rx_data_buf _Rx_data_buf A[12:12]c
_Tx_data::
	.blkb 1
	.dbsym e Tx_data _Tx_data c

⌨️ 快捷键说明

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