-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathPetitModbusPort.c
61 lines (49 loc) · 1.75 KB
/
PetitModbusPort.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
61
#include "PetitModbus.h"
#include "PetitModbusPort.h"
// This port file for PIC microcontrollers!
// Modbus RTU Variables
volatile unsigned char PetitReceiveBuffer[PETITMODBUS_RECEIVE_BUFFER_SIZE]; // Buffer to collect data from hardware
volatile unsigned char PetitReceiveCounter=0; // Collected data number
// UART Initialize for Microconrollers, yes you can use another phsycal layer!
void PetitModBus_UART_Initialise(void)
{
// Insert UART Init Code Here
InitUART();
}
// Timer Initialize for Petit Modbus, 1ms Timer will be good for us!
void PetitModBus_TIMER_Initialise(void)
{
// Insert TMR Init Code Here
InitTMR1();
}
// This is used for send one character
void PetitModBus_UART_Putch(unsigned char c)
{
while(!TRMT);
TXREG = c;
}
// This is used for send string, better to use DMA for it ;)
unsigned char PetitModBus_UART_String(unsigned char *s, unsigned int Length)
{
unsigned short DummyCounter;
for(DummyCounter=0;DummyCounter<Length;DummyCounter++)
PetitModBus_UART_Putch(s[DummyCounter]);
return TRUE;
}
/*************************Interrupt Fonction Slave*****************************/
// Call this function into your UART Interrupt. Collect data from it!
// Better to use DMA
void ReceiveInterrupt(unsigned char Data)
{
PetitReceiveBuffer[PetitReceiveCounter] =Data;
PetitReceiveCounter++;
if(PetitReceiveCounter>PETITMODBUS_RECEIVE_BUFFER_SIZE)
PetitReceiveCounter=0;
PetitModbusTimerValue=0;
}
// Call this function into 1ms Interrupt or Event!
void PetitModBus_TimerValues(void)
{
PetitModbusTimerValue++;
}
/******************************************************************************/