485通信发送数据- #include "stm32f10x.h" // Device header
- #include "usart.h"
- #include "timer.h"
- #include "rs485.h"
- #include "gpio.h"
- /*
- 自定义协议:起始标志+ID+命令+参数+结束标志
- */
- int main()
- {
- u8 key;
- u8 buf[]={0xff,2,2,10,0xfe};
- NVIC_SetPriorityGrouping(5);
- /* 硬件初始化 */
- KEY_Init();
- USART_1_Init(115200);
- Timer_2_Delay_Init();
- RS485_Init(115200);
- printf("M3节点板为接收模式\r\n");
- printf("M4大板发送\r\n");
- while(1)
- {
- key = Key_Scan();
- if(key == 1)
- {
- RS485_Send(buf,5);
- }
-
- if(rs485.rxflag == 1)
- {
- printf("id:%d cmd=%d arg=%d\n",rs485.rxbuf[1],rs485.rxbuf[2],rs485.rxbuf[3]);
- rs485.rxflag = 0;
- }
- }
- }
- /*
- 作业:
- static extern define typedef +举例
- */
复制代码
Keil代码下载:
485_M3_发送.7z
(196.99 KB, 下载次数: 22)
|