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

📄 uart.s

📁 很好的串口调试程序
💻 S
字号:
	.module uart.c
	.area text(rom, con, rel)
	.dbfile uart.c
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 15
; //ICC-AVR application builder : 2005-5-1 15:44:13
; // Target : M16
; // Crystal: 6.0000Mhz
; 
; #include <iom16v.h>
; #include <macros.h>
; 
; #define b19200  ox19
; #define b9600   0x26
; #define baud   b9600
; 
; unsigned char com_in_buf[1];
; 
; void port_init(void)
; {
	.dbline 16
;  PORTA = 0xFF;
	ldi R24,255
	out 0x1b,R24
	.dbline 17
;  DDRA  = 0xFF;
	out 0x1a,R24
	.dbline 18
;  PORTB = 0x00;
	clr R2
	out 0x18,R2
	.dbline 19
;  DDRB  = 0x00;
	out 0x17,R2
	.dbline 20
;  PORTC = 0x00; //m103 output only
	out 0x15,R2
	.dbline 21
;  DDRC  = 0x00;
	out 0x14,R2
	.dbline 22
;  PORTD = 0x00;
	out 0x12,R2
	.dbline 23
;  DDRD  = 0x00;
	out 0x11,R2
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e uart0_init _uart0_init fV
	.even
_uart0_init::
	.dbline -1
	.dbline 32
; }
; 
; //UART0 initialize
; // desired baud rate: 9600
; // actual: baud rate:9615 (0.2%)
; // char size: 8 bit
; // parity: Disabled
; void uart0_init(void)
; {
	.dbline 33
;  UCSRB = 0x00; //disable while setting baud rate
	clr R2
	out 0xa,R2
	.dbline 34
;  UCSRA = 0x00;
	out 0xb,R2
	.dbline 35
;  UCSRC = BIT(URSEL) | 0x06;
	ldi R24,134
	out 0x20,R24
	.dbline 36
;  UBRRL = baud; //set baud rate lo
	ldi R24,38
	out 0x9,R24
	.dbline 37
;  UBRRH = 0x00; //set baud rate hi
	out 0x20,R2
	.dbline 38
;  UCSRB = 0x98;
	ldi R24,152
	out 0xa,R24
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e send_data _send_data fV
;           back -> R16
	.even
_send_data::
	.dbline -1
	.dbline 42
; }
; 
; void send_data(unsigned char back)
; {
L4:
	.dbline 43
L5:
	.dbline 43
;   while( !( UCSRA & (1<<UDRE)) ) ;
	sbis 0xb,5
	rjmp L4
	.dbline 44
;   UDR=back;
	out 0xc,R16
	.dbline -2
L3:
	.dbline 0 ; func end
	ret
	.dbsym r back 16 c
	.dbend
	.area vector(rom, abs)
	.org 44
	jmp _uart0_rx_isr
	.area text(rom, con, rel)
	.dbfile uart.c
	.dbfunc e uart0_rx_isr _uart0_rx_isr fV
	.even
_uart0_rx_isr::
	xcall push_lset
	.dbline -1
	.dbline 49
; }
; 
; #pragma interrupt_handler uart0_rx_isr:12
; void uart0_rx_isr(void)
; {
	.dbline 51
;  //uart has received a character in UDR
;  com_in_buf[0]=UDR;
	in R2,0xc
	sts _com_in_buf,R2
	.dbline 52
;  PORTA =~com_in_buf[0];
	com R2
	out 0x1b,R2
	.dbline 53
;  send_data(com_in_buf[0]);
	lds R16,_com_in_buf
	xcall _send_data
	.dbline -2
L7:
	xcall pop_lset
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 58
; }
; 
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
	.dbline 60
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 61
;  port_init();
	xcall _port_init
	.dbline 62
;  uart0_init();
	xcall _uart0_init
	.dbline 64
; 
;  MCUCR = 0x00;
	clr R2
	out 0x35,R2
	.dbline 65
;  GICR  = 0x00;
	out 0x3b,R2
	.dbline 66
;  TIMSK = 0x00; //timer interrupt sources
	out 0x39,R2
	.dbline 67
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
L8:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fV
;              j -> R20
	.even
_main::
	.dbline -1
	.dbline 72
;  //all peripherals are now initialized
; }
; 
; void main(void)
; {
	.dbline 74
;   char j;
;   init_devices();
	xcall _init_devices
	xjmp L11
L10:
	.dbline 76
;   while(1)
;   {
	.dbline 77
;     for(j=1;j<100;j++)
	ldi R20,1
	xjmp L16
L13:
	.dbline 78
L14:
	.dbline 77
	inc R20
L16:
	.dbline 77
	cpi R20,100
	brlo L13
	.dbline 79
L11:
	.dbline 75
	xjmp L10
X0:
	.dbline -2
L9:
	.dbline 0 ; func end
	ret
	.dbsym r j 20 c
	.dbend
	.area bss(ram, con, rel)
	.dbfile uart.c
_com_in_buf::
	.blkb 1
	.dbsym e com_in_buf _com_in_buf A[1:1]c

⌨️ 快捷键说明

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