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

📄 test.s

📁 avr单片机串口先进先出实例程序
💻 S
字号:
	.module test.c
	.area data(ram, con, rel)
_uart_inter_flag::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile D:\iccavr\mega16\uart\test.c
	.dbsym e uart_inter_flag _uart_inter_flag c
	.area text(rom, con, rel)
	.dbfile D:\iccavr\mega16\uart\test.c
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 11
; //ICC-AVR application builder : 2009-4-2 9:23:34
; // Target : M16
; // Crystal: 7.3728Mhz
; 
; #include <iom16v.h>
; #include <macros.h>
; 
; unsigned char count,uart_inter_flag=0,uart_buf[37];
; 
; void port_init(void)
; {
	.dbline 12
;  PORTA = 0x00;
	clr R2
	out 0x1b,R2
	.dbline 13
;  DDRA  = 0x00;
	out 0x1a,R2
	.dbline 14
;  PORTB = 0x08;
	ldi R24,8
	out 0x18,R24
	.dbline 15
;  DDRB  = 0x08;
	out 0x17,R24
	.dbline 16
;  PORTC = 0x00; //m103 output only
	out 0x15,R2
	.dbline 17
;  DDRC  = 0x00;
	out 0x14,R2
	.dbline 18
;  PORTD = 0x00;
	out 0x12,R2
	.dbline 19
;  DDRD  = 0x00;
	out 0x11,R2
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e timer0_init _timer0_init fV
	.even
_timer0_init::
	.dbline -1
	.dbline 27
; }
; 
; //TIMER0 initialize - prescale:1024
; // WGM: Normal
; // desired value: 10mSec
; // actual value: 10.000mSec (0.0%)
; void timer0_init(void)
; {
	.dbline 28
;  TCCR0 = 0x00; //stop
	clr R2
	out 0x33,R2
	.dbline 29
;  TCNT0 = 0xB8; //set count
	ldi R24,184
	out 0x32,R24
	.dbline 30
;  OCR0  = 0x48;  //set compare
	ldi R24,72
	out 0x3c,R24
	.dbline 31
;  TCCR0 = 0x05; //start timer
	ldi R24,5
	out 0x33,R24
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 36
	jmp _timer0_ovf_isr
	.area text(rom, con, rel)
	.dbfile D:\iccavr\mega16\uart\test.c
	.dbfunc e timer0_ovf_isr _timer0_ovf_isr fV
	.even
_timer0_ovf_isr::
	st -y,R24
	st -y,R25
	in R24,0x3f
	st -y,R24
	.dbline -1
	.dbline 36
; }
; 
; #pragma interrupt_handler timer0_ovf_isr:10
; void timer0_ovf_isr(void)
; {
	.dbline 37
;  TCNT0 = 0xB8; //reload counter value
	ldi R24,184
	out 0x32,R24
	.dbline 38
;  count++;
	lds R24,_count
	subi R24,255    ; addi 1
	sts _count,R24
	.dbline -2
L3:
	ld R24,y+
	out 0x3f,R24
	ld R25,y+
	ld R24,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e uart0_init _uart0_init fV
	.even
_uart0_init::
	.dbline -1
	.dbline 47
; }
; 
; //UART0 initialize
; // desired baud rate: 9600
; // actual: baud rate:9600 (0.0%)
; // char size: 8 bit
; // parity: Disabled
; void uart0_init(void)
; {
	.dbline 48
;  UCSRB = 0x00; //disable while setting baud rate
	clr R2
	out 0xa,R2
	.dbline 49
;  UCSRA = 0x00;
	out 0xb,R2
	.dbline 50
;  UCSRC = BIT(URSEL) | 0x06;
	ldi R24,134
	out 0x20,R24
	.dbline 51
;  UBRRL = 0x2F; //set baud rate lo
	ldi R24,47
	out 0x9,R24
	.dbline 52
;  UBRRH = 0x00; //set baud rate hi
	out 0x20,R2
	.dbline 53
;  UCSRB = 0x98;
	ldi R24,152
	out 0xa,R24
	.dbline -2
L4:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 44
	jmp _uart0_rx_isr
	.area text(rom, con, rel)
	.dbfile D:\iccavr\mega16\uart\test.c
	.dbfunc e uart0_rx_isr _uart0_rx_isr fV
;           temp -> R16
;              i -> R18
	.even
_uart0_rx_isr::
	st -y,R2
	st -y,R16
	st -y,R18
	st -y,R24
	st -y,R25
	st -y,R30
	st -y,R31
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 58
; }
; 
; #pragma interrupt_handler uart0_rx_isr:12
; void uart0_rx_isr(void)
; {
L6:
	.dbline 61
L7:
	.dbline 61
;  //uart has received a character in UDR
;  unsigned char i,temp; 
;  while(!(UCSRA&0x80)); 
	sbis 0xb,7
	rjmp L6
	.dbline 62
;  temp = UDR; 
	in R16,0xc
	.dbline 63
;  for(i=0;i<36;i++) 
	clr R18
	xjmp L12
L9:
	.dbline 64
	ldi R24,<_uart_buf+1
	ldi R25,>_uart_buf+1
	mov R30,R18
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldi R24,<_uart_buf
	ldi R25,>_uart_buf
	mov R30,R18
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R2
L10:
	.dbline 63
	inc R18
L12:
	.dbline 63
	cpi R18,36
	brlo L9
	.dbline 65
;   uart_buf[i]=uart_buf[i+1]; 
;  uart_buf[36]=temp; 
	sts _uart_buf+36,R16
	.dbline 66
;  uart_inter_flag=0x01;
	ldi R24,1
	sts _uart_inter_flag,R24
	.dbline -2
L5:
	ld R2,y+
	out 0x3f,R2
	ld R31,y+
	ld R30,y+
	ld R25,y+
	ld R24,y+
	ld R18,y+
	ld R16,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbsym r temp 16 c
	.dbsym r i 18 c
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 71
; }
; 
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
	.dbline 73
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 74
;  port_init();
	xcall _port_init
	.dbline 75
;  timer0_init();
	xcall _timer0_init
	.dbline 76
;  uart0_init();
	xcall _uart0_init
	.dbline 78
; 
;  MCUCR = 0x00;
	clr R2
	out 0x35,R2
	.dbline 79
;  GICR  = 0x00;
	out 0x3b,R2
	.dbline 80
;  TIMSK = 0x01; //timer interrupt sources
	ldi R24,1
	out 0x39,R24
	.dbline 81
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
L15:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fV
;              i -> R20
	.even
_main::
	.dbline -1
	.dbline 87
;  //all peripherals are now initialized
; }
; 
; //
; void main(void)
; {
	.dbline 89
;  unsigned char i;
;  init_devices();
	xcall _init_devices
	xjmp L18
L17:
	.dbline 92
;  //insert your functional code here...
;  while(1)
;  {
	.dbline 93
;   if(uart_inter_flag==1)
	lds R24,_uart_inter_flag
	cpi R24,1
	brne L20
	.dbline 94
;   {
	.dbline 95
;    uart_inter_flag=0;
	clr R2
	sts _uart_inter_flag,R2
	.dbline 96
;    for(i=0;i<37;i++)
	clr R20
	xjmp L25
L22:
	.dbline 97
	ldi R24,<_uart_buf
	ldi R25,>_uart_buf
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R16,z+0
	clr R17
	xcall _putchar
L23:
	.dbline 96
	inc R20
L25:
	.dbline 96
	cpi R20,37
	brlo L22
	.dbline 98
;     putchar(uart_buf[i]);
;   }
L20:
	.dbline 99
;   if(count>30)
	ldi R24,30
	lds R2,_count
	cp R24,R2
	brsh L26
	.dbline 100
;   {
	.dbline 101
;    count=0;
	clr R2
	sts _count,R2
	.dbline 102
;    PORTB^=(1<<3);
	ldi R24,8
	in R2,0x18
	eor R2,R24
	out 0x18,R2
	.dbline 103
;   }
L26:
	.dbline 104
L18:
	.dbline 91
	xjmp L17
X0:
	.dbline -2
L16:
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbend
	.area bss(ram, con, rel)
	.dbfile D:\iccavr\mega16\uart\test.c
_uart_buf::
	.blkb 37
	.dbsym e uart_buf _uart_buf A[37:37]c
_count::
	.blkb 1
	.dbsym e count _count c

⌨️ 快捷键说明

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