📄 uart.asm
字号:
/* ***********************************************************************
**
** Copyright (C) 2002 Jesper Hansen <jesperh@telia.com> and
** Romuald Bialy (MIS) <romek_b@o2.pl>.
**
**
** Yampp-3/USB - low level support library
**
**
*************************************************************************
**
** This file is part of the yampp system.
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software Foundation,
** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
*************************************************************************
**
** Revision History
**
** when what who why
**
** 2002-09-01 1.0 MIS initial public release
**
*********************************************************************** */
#define __ASSEMBLER__ 1
#define __SFR_OFFSET 0
#include <avr/io.h>
//#include <io-avr.h>
#define __tmp_reg__ r0
#define __zero_reg__ r1
;********************************************************************
;*
;* UART stuff
;*
;********************************************************************
.section .data
uart_receivedflag: .byte 0 ; flag for a received char
.comm uart_rxchar,1 ; buffer for 1 received character
.section .text
.global SIG_UART0_RECV
SIG_UART0_RECV:
push r25
ldi r25,1
sts uart_receivedflag,r25
in r25, UDR0
sts uart_rxchar,r25
pop r25
reti
; r24
; void uart_putchar(u08 Data)
.global uart_putchar
uart_putchar:
cpi r24,'\n' ;new line
brne uart_pc1
ldi r24,'\r'
rcall uart_pc1
ldi r24,'\n'
.global uart_pc1
uart_pc1: in r25, UCSR0A
sbrs r25, UDRE
rjmp uart_pc1
out UDR0, r24
; sbi UCSR0A, TXC // Clear transmission end flag
ret
;u08 uart_getchar(void)
.global uart_getchar
uart_getchar:
lds r24,uart_receivedflag
tst r24
breq uart_getchar
sts uart_receivedflag,__zero_reg__
lds r24,uart_rxchar
clr r25
ret
;u08 uart_haschar(void)
.global uart_haschar
uart_haschar:
lds r24,uart_receivedflag
clr r25
ret
; r25/r24
;void uart_init(u16 BaudRate)
.global uart_init
uart_init:
out UBRRH,r25
out UBRR0, r24
ldi r25, (1 << RXCIE) | (1<<RXEN) | (1<<TXEN)
out UCSR0B, r25
sei
ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -