📄 console.h
字号:
/*********************************************************************
串口通信头文件
*********************************************************************
* 文件名: Console.h
* 描述:
* 处理器: Mega128
* 编译器: WinAVR
*-------------------------------------------------------------------
* 编者 日期 备注
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 陈火健 03/31/06
********************************************************************/
#ifndef _Console_h
#define _Console_h
//.................................................................................................
#define INIT_UART0(baudRate,options) \
do { \
UBRR0H = (baudRate) >> 8; \
UBRR0L = (baudRate); \
UCSR0C = (unsigned char) options; \
if (options > 0xFF) { \
UCSR0B |= 0x04; \
} else { \
UCSR0B &= ~0x04; \
} \
UCSR0A |= (1<<U2X0); \
} while (0)
// Baud rate codes for use with the INIT_UART1 macro
#define UART_BAUDRATE_2K4 416
#define UART_BAUDRATE_4K8 207
#define UART_BAUDRATE_9K6 103
#define UART_BAUDRATE_14K4 68
#define UART_BAUDRATE_19K2 51
#define UART_BAUDRATE_28K8 34
#define UART_BAUDRATE_38K4 25
#define UART_BAUDRATE_57K6 16
#define UART_BAUDRATE_76K8 12
#define UART_BAUDRATE_115K2 8
// Options for use with the INIT_UART1 macro
#define UART_OPT_ONE_STOP_BIT 0
#define UART_OPT_TWO_STOP_BITS 0x08
#define UART_OPT_NO_PARITY 0
#define UART_OPT_EVEN_PARITY 0x20
#define UART_OPT_ODD_PARITY 0x30
#define UART_OPT_5_BITS_PER_CHAR 0
#define UART_OPT_6_BITS_PER_CHAR 0x02
#define UART_OPT_7_BITS_PER_CHAR 0x04
#define UART_OPT_8_BITS_PER_CHAR 0x06
#define UART_OPT_9_BITS_PER_CHAR 0x0406
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
// Enable/disable macros
// Enable/disable UART1
#define ENABLE_UART0() (UCSR0B |= ((1<<RXEN0) | (1<<TXEN0)))
#define DISABLE_UART0() (UCSR0B &= ~((1<<RXEN0) | (1<<TXEN0)))
//#define ENABLE_UART1() (UCSR1B |= (BM(RXEN1) | BM(TXEN1)))
//#define DISABLE_UART1() (UCSR1B &= ~(BM(RXEN1) | BM(TXEN1)))
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
// Macros which are helful when transmitting and receiving data over the serial interface.
//
// Example of usage:
// UART1_SEND(pData[0]);
// for (i = 1; i < len; i++) {
// UART1_WAIT_AND_SEND(pData[i]);
// }
#define UART0_SEND_WAIT() { while (!(UCSR0A & BM(UDRE0))); }
#define UART0_PUTC(x) { UART0_SEND_WAIT(); UDR0=(x); }
#define UART0_RECEIVE_WAIT() { while (!(UCSR0A & BM(RXC0))); }
#define UART0_GETC(x) { UART0_RECEIVE_WAIT();(x)=UDR0;}
#define ConsoleInit() { INIT_UART0(UART_BAUDRATE_9K6,UART_OPT_8_BITS_PER_CHAR|UART_OPT_ONE_STOP_BIT|UART_OPT_NO_PARITY);ENABLE_UART0();}
#define ConsolePut(x) UART0_PUTC(x)
#define ConsoleGet(x) UART0_GETC(x)
#define ConsoleIsPutReady() (UCSR0A & BM(UDRE0))
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -