lpc1700 can通讯例程
单片机源程序如下:
- /****************************************Copyright (c)****************************************************
- **
- **--------------File Info---------------------------------------------------------------------------------
- ** File name: main.c
- ** Last modified Date: 2009-05-12
- ** Last Version: V1.01
- ** Descriptions: The main() function example template
- **
- **--------------------------------------------------------------------------------------------------------
- ** Created by: Chengmingji
- ** Created date: 2009-07-24
- ** Version: V1.00
- ** Descriptions: 添加用户应用程序
- **
- **--------------------------------------------------------------------------------------------------------
- ** Modified by: Liangbaoqiong
- ** Modified date: 2009-07-27
- ** Version: V1.01
- ** Descriptions: 编写CAN例程
- **
- ** Rechecked by: Zhang bin1
- *********************************************************************************************************/
- #include "LPC17xx.h" /* LPC17xx外设寄存器 */
- #include "LPC1700CAN.h"
- /*********************************************************************************************************
- ** Function name: SysDelay
- ** Descriptions: 较为准确的软件延时函数
- ** Input parameters: ulCount: 输入延时值,如该值为主频值,则延时时间为3秒
- ** output parameters: 无
- ** Returned value: 无
- *********************************************************************************************************/
- __asm void SysDelay (uint32_t ulCount)
- {
- subs r0, #1;
- bne SysDelay;
- bx lr;
- }
- extern uint32_t SystemFrequency;
- /*********************************************************************************************************
- ** Function name: main
- ** Descriptions: 测试时短接JP15,逻辑分析仪分别与COM8中CANH和CANL相接,然后打开ZLGCANTest调试软件
- ** 设置波特率为1000kbps,启动观察接收情况
- ** input parameters: 无
- ** output parameters: 无
- ** Returned value: 无
- *********************************************************************************************************/
- int main (void)
- {
- unsigned char ucData11[]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
-
- SystemInit(); /* 系统初始化 */
-
- CAN_Init(0,BPS_10K); /* 初始化CAN1 通道 1M波特率 */
- /*
- * 写报文信息(报文数据长度、是否标准帧、ID、发送数据所在的数组)
- */
- while(!writedetail(8,1, 0x08888888,ucData11));
- while (1) {
- CANSend(0, 2);
- SysDelay(SystemFrequency / 6); /* 延时3/6 s = 500ms */
- }
- }
- /*********************************************************************************************************
- End Of File
- *********************************************************************************************************/
复制代码
所有资料51hei提供下载:
CAN.zip
(789.53 KB, 下载次数: 26)
|