--------------------------serial.h------------------------------------------
#ifndef _SERIAL_H_
#define _SERIAL_H_
#define my_board
#ifdef my_board //只需修改这里,就可移植到STM32等多种支持定时器的单片机中。
void rx_timer_inter(void);
void tx_timer_inter(void);
void init_timer(void);
void start_tx_timer(void);//接收和发送分别采用一个定时器
void start_rx_timer(void);
void stop_rx_timer(void);
void stop_rx_timer(void);
//GPIO模块串口TX
//GPIO模拟串口RX
void init_gpio(void); //配置TX为输出,RX为输入管脚,并设置TX管脚的初始状态为1
unsigned char read_rx_line(void);
void write_tx_line(unsigned char dat);
#endif
//串口信息的结构体
struct serial_t{
unsigned char digital;
unsigned char parriy; //none even odd
unsigned char stop;
unsigned char baud;
};
static struct serial_t serial;
static unsigned char tx_flag=0; //定时器修改此标志
static unsigned char rx_flag=0; //
unsigned char make_odd_bit(unsigned char ch);
unsigned char make_even_bit(unsigned char ch);
unsigned char odd_check(unsigned char ch,unsigned char check);
unsigned char even_check(unsigned char ch,unsigned char check);
void serial_init(void);
unsigned char recv_one_bit(void);
unsigned char is_start_bit(void);
unsigned char is_stop_bit(void);
unsigned char recv_one_byte(unsigned char *ch);
unsigned char recv_n_byte(unsigned char *buf);
void send_one_byte(unsigned char ch);
void send_n_byte(unsigned char *buf,unsigned char num);
#endif
------------------------------------------------------------------
----------------------------serial.c--------------------------------
#include "serial.h"
#include "global.h"
#ifdef my_board
void rx_timer_inter(void)//中断服务程序
{
rx_flag = 1;
}
void tx_timer_inter(voi