#ifndef __RS485__H #define __RS485__H //************************************************************* //RS485_RE/DE初始化PB3/PB4 #define RS485_GpioInit() do{ \ GPIO_Init(GPIOB, GPIO_Pin_3, 1, IO_OUT_PP); \ GPIO_Init(GPIOB, GPIO_Pin_4, 1, IO_OUT_PP); \ }while(0) //RS485_RE输出控制 #define RS485_ReLow() GPIO_ClrBit(GPIOB, GPIO_Pin_3) #define RS485_ReHigh() GPIO_SetBit(GPIOB, GPIO_Pin_3) #define RS485_ReSta() GPIO_ReadPin(GPIOB, GPIO_Pin_3) //RS485_DE输出控制 #define RS485_DeHigh() GPIO_SetBit(GPIOB, GPIO_Pin_4) #define RS485_DeLow() GPIO_ClrBit(GPIOB, GPIO_Pin_4) #define RS485_DeSta() GPIO_ReadPin(GPIOB, GPIO_Pin_4) //************************************************************* enum { RS485_SleepMode = 1, //DE=0,RE=1 RS485_TxMode = 2, //DE=1,RE=0 RS485_RxMode = 3, //DE=1,RE=1 }; #define RS485_Mode(Mode) do{ \ if(Mode & 0x01) RS485_ReHigh(); \ else RS485_ReLow(); \ if(Mode & 0x02) RS485_DeHigh(); \ else RS485_DeLow(); \ }while(0) //************************************************************* #define RS485_SendChar(ch) UART_SendChar(M0P_UART0, ch) //************************************************************* #define RS485_Init() do{ \ RS485_GpioInit(); \ UART_Init(UART0, UART_BOUND_Tab[UART_9600bps], 8, Stop1bit, UartDataOrAddr);\ }while(0) #endif