usart.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef __USART_H__
  2. #define __USART_H__
  3. #include "STM32F10x.h"
  4. #include <string.h>
  5. #include <stdio.h>
  6. #define USART1_RECEIVE_BUFSIZE 100
  7. #define USART1_MAX_SIZE 96
  8. #define USART2_RECEIVE_BUFSIZE 2048
  9. #define USART2_MAX_SIZE 4996
  10. #define second 1000000
  11. #define L_TIME (1*second)
  12. #define Z_TIME (10*second)
  13. #define HH_TIME (90*second)
  14. #define H_TIME (30*second) //设置串口接收的等待时间
  15. #define Usart1ReadLen 20
  16. extern void UART_Config(void);
  17. #define USING_USART1 1
  18. #define USING_USART2 1
  19. #define USING_USART3 1
  20. /***************************USART1**************************/
  21. #if USING_USART1
  22. extern void UART1_bound(u32 bound);
  23. extern void uart1_putchar(u8 ch);
  24. extern void UART1Write(u8 *data,u32 len);
  25. extern u16 UART1_Receiver_buf(u8 *data,u32 len,u32 time); //等待接收数据 接收到的数据,接收到的个数等待接收的时间
  26. #define UASART1_INTOFF() USART_ITConfig(USART1, USART_IT_RXNE,DISABLE)
  27. #define UASART1_INTON() USART_ITConfig(USART1, USART_IT_RXNE,ENABLE)
  28. #endif
  29. /***************************USART2**************************/
  30. #if USING_USART2
  31. extern void UART2_bound(u32 bound);
  32. extern void uart2_putchar(u8 ch);
  33. extern void UART2Write(u8 *data,u32 len);
  34. extern u16 UART2_Receiver_buf(u8 *data,u32 len,u32 time);
  35. #define UASART2_INTOFF() USART_ITConfig(USART2, USART_IT_RXNE,DISABLE)
  36. #define UASART2_INTON() USART_ITConfig(USART2, USART_IT_RXNE,ENABLE)
  37. #endif
  38. /***************************USART3**************************/
  39. #if USING_USART3
  40. extern void UART3_bound(u32 bound);
  41. extern void uart3_putchar(u8 ch);
  42. extern void UART3Write(u8 *data,u32 len);
  43. extern u16 UART3_Receiver_buf(u8 *data,u32 len,u32 time);
  44. #endif
  45. void uart2_putchar(u8 ch); //发送一个字符
  46. extern u8 usa1_buf[USART1_RECEIVE_BUFSIZE];
  47. extern u8 gprs_buf[USART2_RECEIVE_BUFSIZE];
  48. extern vu8 IRQURA2,IRQURA1; //置中断标志位1主函数处理中断
  49. #endif