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

📄 uart.h

📁 实现功能ATmega单片机上处理GSM模块的数据
💻 H
字号:


#ifndef UART_H
#define UART_H

#include "global.h"
#include "buffer.h"

#define UART_DEFAULT_BAUD_RATE	9600

#ifndef UART_TX_BUFFER_SIZE
#define UART_TX_BUFFER_SIZE		0x0040
#endif
#ifndef UART_RX_BUFFER_SIZE

#define UART_RX_BUFFER_SIZE		0x0040
#endif


#ifdef UART_BUFFER_EXTERNAL_RAM
	#define UART_TX_BUFFER_ADDR	0x1000
	#define UART_RX_BUFFER_ADDR	0x1100
#endif

#ifndef UART_INTERRUPT_HANDLER
#define UART_INTERRUPT_HANDLER	SIGNAL
#endif

#ifdef UCSRB
	#define UCR					UCSRB
#endif
#if defined(UBRR) && !defined(UBRRL)
	#define	UBRRL				UBRR
#endif
#if	defined(__AVR_ATmega88__)	|| \
	defined(__AVR_ATmega168__)
	#define UDR					UDR0
	#define UCR					UCSR0B
	#define RXCIE				RXCIE0
	#define TXCIE				TXCIE0
	#define RXC					RXC0
	#define TXC					TXC0
	#define RXEN				RXEN0
	#define TXEN				TXEN0
	#define UBRRL				UBRR0L
	#define UBRRH				UBRR0H
	#define SIG_UART_TRANS		SIG_USART_TRANS
	#define SIG_UART_RECV		SIG_USART_RECV
	#define SIG_UART_DATA		SIG_USART_DATA
#endif
#if	defined(__AVR_ATmega169__)
	#define SIG_UART_TRANS		SIG_USART_TRANS
	#define SIG_UART_RECV		SIG_USART_RECV
	#define SIG_UART_DATA		SIG_USART_DATA
#endif
#if defined(__AVR_ATmega161__)
	#define UDR					UDR0
	#define UCR					UCSR0B
	#define UBRRL				UBRR0
	#define SIG_UART_TRANS		SIG_UART0_TRANS
	#define SIG_UART_RECV		SIG_UART0_RECV
	#define SIG_UART_DATA		SIG_UART0_DATA
#endif
#if defined(__AVR_ATmega128__)
#ifdef UART_USE_UART1
	#define UDR					UDR1
	#define UCR					UCSR1B
	#define UBRRL				UBRR1L
	#define UBRRH				UBRR1H
	#define SIG_UART_TRANS		SIG_UART1_TRANS
	#define SIG_UART_RECV		SIG_UART1_RECV
	#define SIG_UART_DATA		SIG_UART1_DATA
#else
	#define UDR					UDR0
	#define UCR					UCSR0B
	#define UBRRL				UBRR0L
	#define UBRRH				UBRR0H
	#define SIG_UART_TRANS		SIG_UART0_TRANS
	#define SIG_UART_RECV		SIG_UART0_RECV
	#define SIG_UART_DATA		SIG_UART0_DATA
#endif
#endif

void uartInit(void);

void uartInitBuffers(void);

void uartSetRxHandler(void (*rx_func)(unsigned char c));

void uartSetBaudRate(u32 baudrate);

cBuffer* uartGetRxBuffer(void);

cBuffer* uartGetTxBuffer(void);

void uartSendByte(u08 data);

int uartGetByte(void);

u08 uartReceiveByte(u08* data);

u08 uartReceiveBufferIsEmpty(void);

void uartFlushReceiveBuffer(void);

u08 uartAddToTxBuffer(u08 data);

void uartSendTxBuffer(void);

u08  uartSendBuffer(char *buffer, u16 nBytes);

#endif


⌨️ 快捷键说明

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