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

📄 uart_sub.s

📁 16个单片机c语言实验程序
💻 S
字号:
	.module uart_sub.c
	.area text(rom, con, rel)
	.dbfile D:\16实验程序\串口通信\单片机间通信\从机\uart_sub.c
	.area data(ram, con, rel)
	.dbfile D:\16实验程序\串口通信\单片机间通信\从机\uart_sub.c
_rx_data::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\16实验程序\串口通信\单片机间通信\从机\uart_sub.c
	.dbfile D:\16实验程序\串口通信\单片机间通信\从机\uart2.h
	.dbsym e rx_data _rx_data c
_rx_lab::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\16实验程序\串口通信\单片机间通信\从机\uart2.h
	.dbsym e rx_lab _rx_lab c
	.area text(rom, con, rel)
	.dbfile D:\16实验程序\串口通信\单片机间通信\从机\uart2.h
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 6
; #define uchar unsigned char
; uchar rx_data=0,rx_lab=0;
; 
; //端口初始化
; void port_init(void)
; {
	.dbline 7
;  PORTA = 0x00;
	clr R2
	out 0x1b,R2
	.dbline 8
;  DDRA  = 0x00;
	out 0x1a,R2
	.dbline 9
;  PORTB = 0x00;
	out 0x18,R2
	.dbline 10
;  DDRB  = 0x00;
	out 0x17,R2
	.dbline 11
;  PORTC = 0x00; //m103 output only
	out 0x15,R2
	.dbline 12
;  DDRC  = 0x00;
	out 0x14,R2
	.dbline 13
;  PORTD = 0xFF;
	ldi R24,255
	out 0x12,R24
	.dbline 14
;  DDRD  = 0xFF;
	out 0x11,R24
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e uart0_init _uart0_init fV
	.even
_uart0_init::
	.dbline -1
	.dbline 19
; }
; 
; //串行口初始化
; void uart0_init(void)
; {
	.dbline 20
;  UCSRB = 0x00; //disable while setting baud rate
	clr R2
	out 0xa,R2
	.dbline 21
;  UCSRA = 0x00;
	out 0xb,R2
	.dbline 22
;  UCSRC = BIT(URSEL) | 0x06;
	ldi R24,134
	out 0x20,R24
	.dbline 23
;  UBRRL = 0x19; //set baud rate lo
	ldi R24,25
	out 0x9,R24
	.dbline 24
;  UBRRH = 0x00; //set baud rate hi
	out 0x20,R2
	.dbline 25
;  UCSRB = 0x98;
	ldi R24,152
	out 0xa,R24
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 30
; }
; 
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
	.dbline 32
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 33
;  port_init();
	xcall _port_init
	.dbline 34
;  uart0_init();
	xcall _uart0_init
	.dbline 36
; 
;  MCUCR = 0x00;
	clr R2
	out 0x35,R2
	.dbline 37
;  GICR  = 0x00;
	out 0x3b,R2
	.dbline 38
;  TIMSK = 0x00; //timer interrupt sources
	out 0x39,R2
	.dbline 39
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
L3:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e uart_tx _uart_tx fV
;            txc -> R16
	.even
_uart_tx::
	.dbline -1
	.dbline 45
;  //all peripherals are now initialized
; }
; 
; //发送一个字节数据
; void uart_tx(uchar txc)      //send a uchar data
; {
L5:
	.dbline 46
; while(!(UCSRA&(1<<UDRE)));   //check send enable
L6:
	.dbline 46
	sbis 0xb,5
	rjmp L5
X0:
	.dbline 47
; UDR=txc;              
	out 0xc,R16
	.dbline -2
L4:
	.dbline 0 ; func end
	ret
	.dbsym r txc 16 c
	.dbend
	.area vector(rom, abs)
	.org 44
	jmp _uart0_rx_isr
	.area text(rom, con, rel)
	.dbfile D:\16实验程序\串口通信\单片机间通信\从机\uart2.h
	.dbfunc e uart0_rx_isr _uart0_rx_isr fV
	.even
_uart0_rx_isr::
	st -y,R2
	st -y,R24
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 53
; }
; 
; //中断接收
; #pragma interrupt_handler uart0_rx_isr:iv_USART0_RXC
; void uart0_rx_isr(void)
; {
	.dbline 54
; rx_data=UDR;
	in R2,0xc
	sts _rx_data,R2
	.dbline 55
; rx_lab=0x15;
	ldi R24,21
	sts _rx_lab,R24
	.dbline -2
L8:
	.dbline 0 ; func end
	ld R2,y+
	out 0x3f,R2
	ld R24,y+
	ld R2,y+
	reti
	.dbend
	.dbfile D:\16实验程序\串口通信\单片机间通信\从机\uart_sub.c
	.dbfunc e s_ms _s_ms fI
;             aa -> R16,R17
	.even
_s_ms::
	.dbline -1
	.dbline 10
; //串口通信从机程序
; //收到主机发来的数据后发回给主机,并用led显示接收的数据
; #define uint unsigned int
; #include <iom16v.h>
; #include <macros.h>
; #include "uart2.h"
; 
; //延时
; s_ms(uint aa)
; {
	.dbline 11
; for(;aa>0;aa--);
	xjmp L13
L10:
	.dbline 11
L11:
	.dbline 11
	subi R16,1
	sbci R17,0
L13:
	.dbline 11
	cpi R16,0
	cpc R16,R17
	brne L10
X1:
	.dbline -2
L9:
	.dbline 0 ; func end
	ret
	.dbsym r aa 16 i
	.dbend
	.dbfunc e main _main fI
	.even
_main::
	.dbline -1
	.dbline 16
; }
; 
; //主函数
; main()
; {
	.dbline 17
; init_devices();  //初始化
	xcall _init_devices
	.dbline 18
; DDRD=0xff;
	ldi R24,255
	out 0x11,R24
	.dbline 19
; PORTD=0x00;
	clr R2
	out 0x12,R2
	.dbline 20
; s_ms(60000);
	ldi R16,60000
	ldi R17,234
	xcall _s_ms
	xjmp L16
L15:
	.dbline 22
; while(1)
; 		{
	.dbline 23
; 		if(rx_lab==0x15)//中断标志
	lds R24,_rx_lab
	cpi R24,21
	brne L18
X2:
	.dbline 24
; 		  {
	.dbline 25
; 		  PORTD=~rx_data<<2; //数码管低两位用于串口通信指示
	lds R2,_rx_data
	com R2
	lsl R2
	lsl R2
	out 0x12,R2
	.dbline 26
; 		  uart_tx(rx_data);  //向主机发回收到的数据
	lds R16,_rx_data
	xcall _uart_tx
	.dbline 27
; 		  rx_lab=0;
	clr R2
	sts _rx_lab,R2
	.dbline 28
; 		  }
L18:
	.dbline 29
; 		}
L16:
	.dbline 21
	xjmp L15
X3:
	.dbline -2
L14:
	.dbline 0 ; func end
	ret
	.dbend
; }

⌨️ 快捷键说明

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