📄 main.c
字号:
//****************************************************************************
// @Module Project Settings
// @Filename MAIN.C
// @Project TWINCAN.dav
//----------------------------------------------------------------------------
// @Controller Infineon XC164CS-16F
//
// @Compiler Keil
//
// @Codegenerator 2.7
//
// @Description This file contains the project initialization function.
//
//----------------------------------------------------------------------------
// @Date 12/17/2004 7:07:08 PM
//
//****************************************************************************
// USER CODE BEGIN (MAIN_General,1)
// USER CODE END
//****************************************************************************
// @Project Includes
//****************************************************************************
#include "MAIN.H"
// USER CODE BEGIN (MAIN_General,2)
// USER CODE END
//****************************************************************************
// @Macros
//****************************************************************************
// USER CODE BEGIN (MAIN_General,3)
// USER CODE END
//****************************************************************************
// @Defines
//****************************************************************************
// USER CODE BEGIN (MAIN_General,4)
extern struct stCanObj
{
ubyte ubData[8]; // Message Data 0..7
ulong ulCANAR; // Arbitration Register
ulong ulCANAMR; // Acceptance Mask Register
uword uwMSGCTR; // Message Control Register
uword uwCounter; // Frame Counter
uword uwMSGCFG; // Message Configuration Register
uword uwINP; // Interrupt Node Pointer
uword uwCANFCR; // FIFO / Gateway Control Register
uword uwCANPTR; // FIFO Pointer
ulong ulReserved; // Reserved
};
// USER CODE END
//****************************************************************************
// @Typedefs
//****************************************************************************
// USER CODE BEGIN (MAIN_General,5)
// USER CODE END
//****************************************************************************
// @Imported Global Variables
//****************************************************************************
// USER CODE BEGIN (MAIN_General,6)
// USER CODE END
//****************************************************************************
// @Global Variables
//****************************************************************************
// USER CODE BEGIN (MAIN_General,7)
unsigned char KeyBuf[12] = {'r', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
unsigned char WriteIndex = 1;
unsigned char ReadIndex = 0;
unsigned int CursorPosX;
unsigned int CursorPosY;
unsigned int MO_Status[32]= {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
TCAN_SWObj SW_MOs[32];
unsigned int MenuID=0;
// USER CODE END
//****************************************************************************
// @External Prototypes
//****************************************************************************
// USER CODE BEGIN (MAIN_General,8)
// USER CODE END
//****************************************************************************
// @Prototypes Of Local Functions
//****************************************************************************
// USER CODE BEGIN (MAIN_General,9)
// USER CODE END
//****************************************************************************
// @Function void MAIN_vInit(void)
//
//----------------------------------------------------------------------------
// @Description This function initializes the microcontroller.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 12/17/2004
//
//****************************************************************************
// USER CODE BEGIN (Init,1)
// USER CODE END
void MAIN_vInit(void)
{
// USER CODE BEGIN (Init,2)
// USER CODE END
/// -----------------------------------------------------------------------
/// Configuration of the System Clock:
/// -----------------------------------------------------------------------
/// - VCO clock used, input clock is connected
/// - input frequency is 8 MHz
/// - VCO output frequency 150 .. 200 MHz
/// - system clock is 40 MHz
MAIN_vUnlockProtecReg(); // unlock write security
PLLCON = 0x7343; // load PLL control register
//// -----------------------------------------------------------------------
//// Begin of Important Settings for the Start-Up File
//// -----------------------------------------------------------------------
/// All following settings must be set in the start-up file. You can use
/// DAvE's project file (*.dpt) to include this register values into your
/// compiler EDE.
/// ---------------------------------------------------------------------
/// Initialization of the CPUCON1 Register:
/// ---------------------------------------------------------------------
/// - space between two vectors is 2 words
/// - DISWDT executable until End of Init
/// - segmentation is enabled
/// - switch context is interruptible
/// - branch prediction is enabled
/// - zero cycle jump function is enabled
//// this register must be set in the start-up file
//// CPUCON1 = 0x0007
/// ---------------------------------------------------------------------
/// Initialization of the VECSEG Register:
/// ---------------------------------------------------------------------
/// - start from external memory
//// this register must be set in the start-up file
//// VECSEG = 0x0000
/// ---------------------------------------------------------------------
/// Initialization of the SYSCON0 Register:
/// ---------------------------------------------------------------------
//// this register must be set in the start-up file
//// SYSCON0 = 0x0000
/// ---------------------------------------------------------------------
/// Initialization of the SYSCON1 Register:
/// ---------------------------------------------------------------------
/// clock prescaler for system is fpll / 1
//// this register must be set in the start-up file
//// SYSCON1 = 0x0000
/// ---------------------------------------------------------------------
/// Initialization of the SYSCON3 Register:
/// ---------------------------------------------------------------------
//// this register must be set in the start-up file
//// SYSCON3 = 0x0000
/// ---------------------------------------------------------------------
/// Initialization of EBC
/// ---------------------------------------------------------------------
//// this register must be set in the start-up file
//// EBCMOD1 = 0x007F
/// EBC is disabled
//// -----------------------------------------------------------------------
//// End of Important Settings for the Start-Up File
//// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Initialization of the Peripherals:
// -----------------------------------------------------------------------
// initializes the Asynchronous/Synchronous Serial Interface (ASC0)
ASC0_vInit();
// initializes the General Purpose Timer Unit (GPT1)
GPT1_vInit();
// initializes the TwinCAN Module (CAN)
CAN_vInit();
// USER CODE BEGIN (Init,3)
// USER CODE END
// globally enable interrupts
PSW_IEN = 1;
} // End of function MAIN_vInit
//****************************************************************************
// @Function void MAIN_vUnlockProtecReg(void)
//
//----------------------------------------------------------------------------
// @Description This function makes it possible to write one protected
// register. After calling of this function and write on the
// protected register is the security level set to low
// protected mode.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 12/17/2004
//
//****************************************************************************
// USER CODE BEGIN (UnlockProtecReg,1)
// USER CODE END
void MAIN_vUnlockProtecReg(void)
{
ubyte ubPASSWORD;
if((SCUSLS & 0x1800) == 0x0800) // if low protected mode
{
ubPASSWORD = SCUSLS & 0x00FF;
ubPASSWORD = ~ubPASSWORD;
SCUSLC = 0x8E00 | ubPASSWORD; // command 4
} // end if low protected mode
if((SCUSLS & 0x1800) == 0x1800) // if write protected mode
{
SCUSLC = 0xAAAA; // command 0
SCUSLC = 0x5554; // command 1
ubPASSWORD = SCUSLS & 0x00FF;
ubPASSWORD = ~ubPASSWORD;
SCUSLC = 0x9600 | ubPASSWORD; // command 2
SCUSLC = 0x0800; // command 3; new PASSWOR is 0x00
ubPASSWORD = SCUSLS & 0x00FF;
ubPASSWORD = ~ubPASSWORD;
SCUSLC = 0x8E00 | ubPASSWORD; // command 4
} // end if write protected mode
} // End of function MAIN_vUnlockProtecReg
//****************************************************************************
// @Function void main(void)
//
//----------------------------------------------------------------------------
// @Description This is the main function.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 12/17/2004
//
//****************************************************************************
// USER CODE BEGIN (Main,1)
// USER CODE END
void main(void)
{
// USER CODE BEGIN (Main,2)
unsigned int i;
// USER CODE END
MAIN_vInit();
// USER CODE BEGIN (Main,4)
// USER CODE BEGIN (Main,4)
for (i = 0; i<32; i++)
CAN_HWOBJ[i].uwMSGCTR = 0xff7f; // disable MO
while(1)
{
}
// USER CODE END
} // End of function main
// USER CODE BEGIN (MAIN_General,10)
// USER CODE END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -