51单片机的串口结构

说明目前主要封装了串口1的实例,采用可移植数据类型,可以同步移植到STM32、STM8等单片机;需自行实现串口接收回调函数内容;欢迎各位指正并分享;头文件#ifndef __SERIAL_H__#define __SERIAL_H__#include <reg52.h>#ifndef uint8_ttypedef unsigned char uint8_t;#endif#ifndef uint16_ttypedef unsigned int uint16_t;
摘要由CSDN通过智能技术生成

说明

  1. 目前主要封装了串口1的实例,采用可移植数据类型,可以同步移植到STM32、STM8等单片机;
  2. 需自行实现串口接收回调函数内容;
  3. 欢迎各位指正并分享;

头文件

#ifndef __SERIAL_H__
#define __SERIAL_H__

#include <reg52.h>

#ifndef uint8_t
typedef unsigned char uint8_t;
#endif

#ifndef uint16_t
typedef unsigned int uint16_t;
#endif

#ifndef uint32_t
typedef unsigned long uint32_t;
#endif

/* 晶振频率 */
#define FOSC 11059200L
/* 单片机周期数,默认为12T */
#define FOSC_DIV 12
/* 接收缓冲区大小 */
#define RECV_BUF_SIZE 64

/* 波特率列表 */
#define	BAUD_2400 2400L
#define BAUD_4800 4800L
#define	BAUD_9600 9600L
#define	BAUD_14400 14400L
#define	BAUD_19200 19200L // 使用此波特率需要加倍
#define	BAUD_38400 38400L // 使用此波特率及以上,1T单片机才支持,或者修改晶振频率
#define	BAUD_43000 43000L
#define	BAUD_57600 57600L
#define	BAUD_115200 115200L
#define	BAUD_230400 230400L
#define	BAUD_460800 460800L

/* 校验类型 */
typedef enum
{
   
	NONE_PARITY = 0, /* 无校验 */
	ODD_PARITY, /* 奇校验 */
	EVEN_PARITY, /* 偶校验 */
	MARK_PARITY, /* Mark parity */
	SPACE_PARITY, /* Space parity  */
} EtypeParity;

/* 串口模式 */
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值