?? candemo.c
字號:
/*----------------------------------------------------------------------------
QQ: 958664258
21IC用戶名:banhushui
交流平臺:http://blog.21ic.com/user1/5817/index.html
淘寶店鋪:http://shop58559908.taobao.com
旺旺:半壺水電子
編譯器版本:MDK4.12
*---------------------------------------------------------------------------*/
#include <stm32f10x_lib.h> // STM32F10x Library Definitions
#include "STM32_Reg.h" // STM32 register and bit Definitions
#include "STM32_Init.h" // STM32 Initialization
#include "CAN.h" // STM32 CAN adaption layer
#include "MyType.h"
#include "config.h"
//為了保證CAN通信的效率,本例子只有CAN初始化配置函數才使用ST官方庫函數
//
/*----------------------------------------------------------------------------
insert a delay time.
*----------------------------------------------------------------------------*/
void delay(unsigned int nCount)
{
for (; nCount != 0; nCount--)
;
}
/*----------------------------------------------------------------------------
initialize CAN interface
*----------------------------------------------------------------------------*/
void can_Init(void)
{
CAN_setup(); // setup CAN interface
CAN_wrFilter(33, STANDARD_FORMAT); // Enable reception of messages
/* COMMENT THE LINE BELOW TO ENABLE DEVICE TO PARTICIPATE IN CAN NETWORK */
//CAN_testmode(CAN_BTR_SILM | CAN_BTR_LBKM); // Loopback, Silent Mode (self-test)
//軟件仿真使用環回模式
//CAN_testmode(CAN_BTR_SILM | CAN_BTR_LBKM); /* Loopback and */
//硬件仿真使用正常模式
CAN_testmode(0); //正常模式
CAN_start(); // leave init mode
CAN_waitReady(); // wait til mbx is empty
}
/*----------------------------------------------------------------------------
MAIN function
*----------------------------------------------------------------------------*/
int main(void)
{
uint32 i;
//uint8 flag=0;
stm32_Init();
can_Init(); // initialise CAN interface
CAN_TxMsg.id = 33; // initialise message to send
for (i = 0; i < 8; i++)
CAN_TxMsg.data[i] = 0;
CAN_TxMsg.len = 4;
CAN_TxMsg.format = STANDARD_FORMAT;
CAN_TxMsg.type = DATA_FRAME;
i = 0;
while (1)
{
if (CAN_TxRdy)
{
if (++i == 60000)
{
//i=0;
CAN_TxMsg.data[0] = 0;
CAN_TxMsg.data[1] = 0;
CAN_TxMsg.data[2] = 0;
CAN_TxMsg.data[3] = 0;
CAN_TxRdy = 0;
CAN_wrMsg(&CAN_TxMsg);
}
else if (i == 120000)
{
i = 0;
CAN_TxMsg.data[0] = 1;
CAN_TxMsg.data[1] = 1;
CAN_TxMsg.data[2] = 1;
CAN_TxMsg.data[3] = 1;
CAN_TxRdy = 0;
CAN_wrMsg(&CAN_TxMsg);
}
}
if (CAN_RxRdy)
{
CAN_RxRdy = 0;
if (CAN_RxMsg.data[0] == 0)////PC8狀
PC8 = 0;
else
PC8 = 1;
if (CAN_RxMsg.data[1] == 0)////PC9狀
PC9 = 0;
else
PC9 = 1;
if (CAN_RxMsg.data[2] == 0)////PC10狀
PC10 = 0;
else
PC10 = 1;
if (CAN_RxMsg.data[3] == 0)////PC11狀
PC11 = 0;
else
PC11 = 1;
}
} // end while
} // end main
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -