📄 main.c
字号:
#include "LIN_Header.h"
void PowerON(void);
/*
SPI Communication Module Test Project
2005-07-07
Wang Junpeng
Update date: 2005 - 07 -11
Author: Wang junpeng
Contents: use interrupt method to reliaze spi communication
1. function SPI_Enable's parameters is modified to SPI_ENABLE, MC33993_INT_ENABLE
2. modified main function's state machine
3. spi communication timeout state checked in main funciton
Update 2005 - 07 - 12
Author: Wang junpeng
Contents:
1. switch state debounce and signal conversion process moved out from the spi data receiving process
2. Add sci communication in the single mcu process by call LIN_Send funciton
*/
void main(void)
{
L_U16 wTime;
PowerON();
#if LIN_DEBUG_MODE == 1
LIN_TEST_PIN_IC_MASK = 1;
LIN_TEST_PIN_SCI_MASK = 1;
LIN_TEST_PIN_IC = 0;
LIN_TEST_PIN_SCI = 0;
LIN_Debug_PIN_BREAK_MASK = 1;
LIN_Debug_PIN_SYNCH_MASK = 1;
LIN_Debug_PIN_ID_MASK = 1;
LIN_Debug_PIN_DATA_MASK = 1;
LIN_Debug_PIN_CHECK_MASK = 1;
LIN_Debug_PIN_BREAK = 0;
LIN_Debug_PIN_SYNCH = 0;
LIN_Debug_PIN_ID = 0;
LIN_Debug_PIN_DATA = 0;
LIN_Debug_PIN_CHECK = 0;
#endif
CmbSwt_Init();
SPI_Init();
LIN_Sys_Init();
LIN_Connect();
MC33993_stInitialized = MC33993_INIT_NONE;
wTime = LIN_GetCurrentTime();
SPI_Enable(SPI_ENABLE, SPI_INT_SEL);
while(1)
{
//MC33993_SG_Wet(nSGLSetting,nSGHSetting);
//1. we are waiting for MC33993's data
if(SPIBuf.mState != SPI_XMT_IDLE)
{
//1.1 Check MC33993 Communication status
if(LIN_CheckTimeOut(SPIBuf.mTimer, LIN_GetCurrentTime(), SPI_ERR_TIMEOUT))
{
//1.1.1 MC33993 communicating timeout
//Clear all tx/rx flag & error flag
//SPIBuf.mState |= SPI_ERR_NORESPONSE;
//SPIBuf.mState &= ~SPI_RX_REQ;
//SPIBuf.mState &= ~SPI_TX_REQ;
SPCR_SPTIE = 0;
Select_MC33993(MC33993_DESEL);
SPIBuf.mState = SPI_XMT_IDLE;
//1.1.2 should we reset MC33993? No. we can't communicate with MC33993
// so all the command we send out are invalid.
//KeyBoard_INT_Enable();
}
}
// else if((SPIBuf.mState & SPI_OVRF) == SPI_OVRF)
// {
// SPIBuf.mState = SPI_XMT_IDLE;
// SPCR_SPTIE = 0;
// Select_MC33993(MC33993_DESEL);
// }
//2. data received by spi, this can be move to SPI_Rx_Indicator
//else if((SPIBuf.mState & SPI_RX_FULL) == SPI_RX_FULL)
//{//this condition was not occured
//TEST_PIN_SG8 = ~TEST_PIN_SG8;
//MC33993_Data_Processing();
//1. all data are received, do extract work now.
//MC33993_Data_Received();
//2. Clear spibuf state
//SPIBuf.mState = SPI_XMT_IDLE;
//3. add sci debug code, send spi data through sci interface
//LIN_SendData(SPI_Rx_Buf[MC33993_DATA_LOW]);
//}
//3. should we start debounce work here ? No. we should start debounce in the main loop
//4. should we start signal conversion process here? No. we should start signal conversion in the main loop
//set test pin to see what we got
TEST_PIN_SG7 = SW_TurnRight;
//5. switch state sample phase should be less the debounce time
// switch state debounce time is 20 ms
// so we sample switch status every 10 ms
if(LIN_CheckTimeOut(wTime, LIN_GetCurrentTime(), 10))
{
wTime = LIN_GetCurrentTime();
TEST_PIN_SG0 = ~TEST_PIN_SG0;
//5.1 MC33993 communication is in idle state?
if(SPIBuf.mState == SPI_XMT_IDLE)
{
//5.1.1 update currenttime
// wTime = LIN_GetCurrentTime();
// //5.1.2 Start spi communication with MC33993
TEST_PIN_SG1 = 1;
MC33993_GetInput();//this sentence was executed
}
}
#if SPI_DEBUG_MODE == 1
// SPI_Debug();
#endif
}
//The Following Code about LINs Add
//-----------------------------------------------------------------------------
KeyBoard_Init();
//-----------------------------------------------------------------------------
KeyBoard_INT_Enable();
}
void PowerON(void)
{
CONFIG2 = CFG2_OSCENINSTOP ;//+ CFG2_ESCIBDSRC;
//1. Disable MSCAN08
//2. Disables extra divide-by-128 prescaler in timebase module
//3. OSC Enabled in STOP Mode
//4. ESCI use internal Data bus clock?External OSC Clock
CONFIG1 = CFG1_COPRS + CFG1_LVIPWRD + CFG1_LVI5OR3 + CFG1_STOP + CFG1_COPD;
//1. timeout period = 2^13 - 2 ^ 4 COPCLK cycles
//2. LVI disabled during stop mode
//3. LVI module resets enabled
//4. LVI module power Disabled
//5. LVI operates in 5-V mode
//6. Stop mode recovery after 4096 CGMXCLCK cycles
//7. STOP instruction enabled
//8. COP module disabled
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -