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

📄 usart.h

📁 MICROCHIP PIC16F6XX USART DRIVER
💻 H
字号:
#ifndef _SERIAL_H_
#define _SERIAL_H_

#include "dtypes.h"

#define BAUD		9600      
#define FOSC		4000000L
#define NINE		0		/* Use 9bit communication? FALSE=8bit */

#define DIVIDER		((int)(FOSC/(16UL * BAUD) -1))
#define HIGH_SPEED	1

#if NINE == 1
#define NINE_BITS	0x40
#else
#define NINE_BITS	0
#endif

#if HIGH_SPEED == 1
#define SPEED		0x4
#else
#define SPEED		0
#endif

#if defined(_16F87) || defined(_16F88)
	#define RX_PIN	TRISB2
	#define TX_PIN	TRISB5
#elif defined(_16F687) || defined(_16F689)|| defined(_16F690)
	#define RX_PIN	TRISB5
	#define TX_PIN	TRISB7
#else
	#define RX_PIN	TRISC7
	#define TX_PIN	TRISC6
#endif

void	USART_Init(void);
void	USART_PutByte(u8 byte);
u8		USART_GetByte(void);
void	USART_PutNinth(u8 byte);
u8		USART_GetNinth(void);
u8		USART_GetFERR(void);
u8		USART_CheckOERR(void);

/* Serial initialization */
#define init_comms()			\
{								\
	RX_PIN = 1;					\
	TX_PIN = 0;		  			\
	ANSELH = 0x00;				\
	SPBRG = DIVIDER;    		\
	RCSTA = (NINE_BITS | 0x90);	\
	TXSTA = (SPEED | NINE_BITS);\
	SPEN = 1;		  			\
	SYNC = 0;		  			\
	TXEN = 1;					\
	CREN = 1;					\
}

void	putch(u8);
u8		getch(void);
u8		getche(void);

#endif

⌨️ 快捷键说明

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