forked from whchoi/Modbus-Slave-for-PIC18F
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
60 lines (52 loc) · 2.45 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/******************************************************************************/
/* Files to Include */
/******************************************************************************/
#if defined(__XC)
#include <xc.h> /* XC8 General Include File */
#elif defined(HI_TECH_C)
#include <htc.h> /* HiTech General Include File */
#include <usart.h>
#elif defined(__18CXX)
#include <p18cxxx.h> /* C18 General Include File */
#include <usart.h>
#endif
#if defined(__XC) || defined(HI_TECH_C)
#include <stdint.h> /* For uint8_t definition */
#include <stdbool.h> /* For true/false definition */
#endif
#include "system.h" /* System funct/params, like osc/peripheral config */
#include "user.h" /* User funct/params, such as InitApp */
#include "modbus.h"
/******************************************************************************/
/* Modbus Global Variable Declaration */
/******************************************************************************/
volatile unsigned int HoldingRegister[50] = {0};
volatile unsigned int InputRegister[50] = {0};
volatile unsigned char Coils[50] = {0};
volatile unsigned char InputBits[50] = {0};
volatile unsigned char Response[125] = {0}; //Enough to return all holding-r's
volatile unsigned char Received[125] = {0}; //Enough to write all holding-r's
volatile char ModbusMessage,MessageLength;
/******************************************************************************/
/* Main Program */
/******************************************************************************/
void main(void)
{
OpnUSART();
ConfigInterrupts();
//The InitPorts procedute initializes your ports
InitPorts(); //configure your ports in user.c under InitPorts
//The Iitiaize procedure is called before the program begins
//commands here will only run once at program start
Initialize(); //enter you initialization code in user.c under Initialize
//main program loop
while(1){
if(ModbusMessage){
DecodeIt();
//The modbusEvents procedure is called when a Modbus message is received
ModbusEvents(); //enter your code in user.c under ModbusEvents
}
//The ProgramLoop procedure will run in an endless loop forever
ProgramLoop(); //enter your code in user.c under ProgramLoop
}
}