📄 example_master.c
字号:
#include <p18cxxx.h>
#include "LIN_appl.h" // created from ldf file
#include "LINbasic.h"
/************************************************************************************************/
/* 10/05/05 JX changed l_ifc_rxtx_MyLinlfc(void) to l_ifc_rx_MyLinlfc(void) */
/* */
/************************************************************************************************/
#define k1MS_TICK SysTimeBase(1000) // give constant value for 1000祍 time tick
#define TMR1IF PIR1bits.TMR1IF
/************************************************************************************************/
_ifc_status lin_status; // the typedef of ifcstatus is defined in LINbasic.h
l_u8 ticks;
l_u8 task;
/************************************************************************************************/
void InterruptHandlerHigh(void);
//void InterruptHandlerLow(void);
#pragma code newIntHigh = 0x08 // 0x208
void newIntHigh(void)
{
_asm goto InterruptHandlerHigh _endasm
}
#pragma code
#pragma interruptlow InterruptHandlerHigh save = PROD
void InterruptHandlerHigh(void)
{
l_ifc_rx_MyLinIfc(); /* call the driver */
if (TMR1IF == 1) /* timer1 is configured as 1ms timer */
{
// PORTBbits.RB0 = !LATBbits.LATB0;
l_wr_TMR(1,~k1MS_TICK);
if(0 == (--ticks))
{
l_ifc_StartMaster(NormalTable[task].pid); /* start transmission after a defined delay */
ticks = NormalTable[task].ticks; /* setup the delay for next start of transmission */
task++;
if (task == sizeof(NormalTable)/sizeof(NormalTable[0]))
{
task = 0; /* check if all frames had been transmitted */
}
}
TMR1IF = 0; /* then reset task to begin again */
}
}
#pragma code
/************************************************************************************************/
#define WaitMCP Delay100TCYx(255)
#define MCP201CSHIGH { _CS_DATA_HIGH; WaitMCP;}
#define MCP201CSLOW { _CS_DATA_LOW; WaitMCP; }
#define MCP201ON() { MCP201CSLOW MCP201CSHIGH MCP201CSLOW MCP201CSHIGH }
l_bool l_ifc_connect_MyLinIfc(void)
{
#ifdef _USE_MCP201
MCP201ON();
#else
_CS_DATA_LOW;
#endif
return 0;
}
l_bool l_ifc_disconnect_MyLinIfc(void)
{
#ifdef _USE_MCP201
MCP201CSLOW;
#else
_CS_DATA_HIGH;
#endif
return 0;
}
/************************************************************************************************/
void InitTimer1(unsigned int value)
{
l_wr_TMR(1,~value);
T1CON = 0x05; // prescale 1:1, internal clock,
TMR1IF = 0;
IPR1bits.TMR1IP = 1;
PIE1bits.TMR1IE = 1;
}
/************************************************************************************************/
void LinCOM(void)
{
static l_u8 help;
lin_status.w = l_ifc_read_status_MyLinIfc();
/* check if transfer is finished and not more than one message has been received since last status check */
if ((lin_status.b.Successful_transfer) && ( 0 == lin_status.b.Overrun))
{
if ( lin_status.b.LastFrame_PID == botSP_MControl_pid)
{
}
else
if (lin_status.b.Error_In_Response)
{
}
}
}
/************************************************************************************************/
void main(void)
{
l_ifc_init_MyLinIfc(); /* initialize the driver */
l_ifc_connect_MyLinIfc(); /* get the physical connection to LIN */
TRISBbits.TRISB0 = 0;
InitTimer1(k1MS_TICK);
ticks = 10; /* start transmission with 10ms delay */
task = 0;
RCONbits.IPEN = 1;
INTCON |= 0xC0; /* enable the interrupt */
l_ifc_wake_up_MyLinIfc(); /* wakup the bus */
for(;;)
{
ClrWdt();
LinCOM(); /* check Status of driver */
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -