📄 modbus.c
字号:
#include <string.h>#include "ModBusDef.h"#include "uart.h"#include "nucleus.h"#include "mototype.h"#include "flash_extr.h"extern char Task_Suspended;extern NU_TASK _Modbus_Task;extern int sound_flag;extern unsigned long TMD_System_Clock;MOD_BUF MOD_sendbuf;extern int Alarm_Info ;extern int Break_Info ;extern void testtest(void);void Change_BootAdd(void);void init_ModBus_DataAdd(void);_MOD_ReciveBUF MOD_revbuf; _ModBus_DataAdd ModBus_DataAdd;//_UART_ReciveData UART_ReciveData;/********************************************************************************************* main function for this file ********************************************************************************************///#ifdef ASCII_MODEconst U8 char_tab[128] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };const U8 tab_char[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};//#endif // ENDOF #ifdef ASCII_MODEvoid MOD_init(void){ /***portB6 置零 收******/ *(volatile unsigned long *)PORTB_DIR &= ~(0x1 << 6); *(volatile unsigned long *)PORTB_SEL |= 0x1<<6; *(volatile unsigned long *)PORTB_DATA &= ~(0x1 << 6); init_ModBus_DataAdd(); memset(&MOD_sendbuf, 0, sizeof(MOD_BUF)); memset(&MOD_revbuf, 0, sizeof(_MOD_ReciveBUF));}/**************************************************************** * psrc: 寰呭彂鏁版嵁鎸囬拡 lenth:寰呭彂鏁版嵁闀垮害 * return 0 is OK * when return num >0 ,that must be something statr ****************************************************************/int MOD_write_sendBuf(RP8 psrc, int lenth){ if (LEFT(MOD_sendbuf) < lenth) { return MOD_SEND_BUFFER_FULL; } psrc = psrc+lenth-1; while(lenth--) { PUTCH(*psrc--, MOD_sendbuf); } return 0;}/**************************************************************** * pdes: 璇诲叆鏁版嵁瀛樻斁澶勬寚閽
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -