📄 example_slave.c
字号:
#include <p18cxxx.h>
#include "LIN_appl.h" // created from ldf file
#include "LINbasic.h"
#include "BLDC_DATA.h"
#include "application.h"
/************************************************************************************************/
/* 10/05/05 JX changed l_ifc_rxtx_MyLinlfc(void) to l_ifc_rx_MyLinlfc(void) */
/* */
/************************************************************************************************/
/************************************************************************************************/
_u_ifc_status lin_status; // the typedef of ifcstatus is defined in LINbasic.h
/************************************************************************************************/
void InterruptHandlerHigh(void);
/************************************************************************************************/
#pragma code newIntHigh = 0x08
void newIntHigh(void){
_asm goto InterruptHandlerHigh _endasm }
#pragma code
/************************************************************************************************/
#pragma interruptlow InterruptHandlerHigh save = PROD//,section(".tmpdata")
void InterruptHandlerHigh(void)
{
l_ifc_rx_MyLinIfc(); /* call the driver */
Update_Sequence();
if (1 == PIR3bits.IC1IF)
{
if (1 == PORTAbits.RA2)
{
LED1 = 1;
}
else
{
LED1 = 0;
}
PIR3bits.IC1IF = 0;
}
else
if ( 1 == PIR3bits.IC2QEIF)
{
if (1 == PORTAbits.RA3)
{
LED2 = 1;
}
else
{
LED2 = 0;
}
PIR3bits.IC2QEIF = 0;
}
else
if (1 == PIR3bits.IC3DRIF)
{
if (1 == PORTAbits.RA4)
{
LED3 = 1;
}
else
{
LED3 = 0;
}
PIR3bits.IC3DRIF = 0;
}
// else
// if ( 1 == PIR1bits.ADIF) // read ADCresults and update registes
// {
// Update_ADC();
// }
}
#pragma code
/************************************************************************************************/
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 == kbotSP_MControl_pid)
{
if ((l_bool_rd_Motor_left ()) && !(l_bool_rd_Motor_right ()))
{
Motor_Turn_Fwd();
}
else
if (!(l_bool_rd_Motor_left ()) && (l_bool_rd_Motor_right ()))
{
Motor_Turn_Rev();
}
else
{
Motor_Stop();
}
}
else
if (lin_status.b.Error_In_Response)
{
botSpMStatus._c[7]++; /* increment error counter */
}
}
}
/************************************************************************************************/
#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)
{
MCP201ON();
return 0;
}
l_bool l_ifc_disconnect_MyLinIfc(void)
{
MCP201CSLOW;
return 0;
}
/************************************************************************************************/
void main(void)
{
Init_Application();
l_ifc_init_MyLinIfc(); /* initialize the driver */
l_ifc_connect_MyLinIfc(); /* get the physical connection to LIN */
l_ifc_goto_sleep_req_MyLinIfc(); /* wait for wakeup sequence */
INTCON |= 0xC0; /* enable the interrupt */
for(;;)
{
ClrWdt();
LinCOM(); /* check Status of driver */
Update_Application();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -