⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 ADS下的测试通过的CAN总线的程序.好东西啊!
💻 C
字号:
#include "../inc/drivers.h"
#include "../inc/lib.h"
#include <string.h>
#include <stdio.h>
#include "../inc/MCP2510.h"
#include "../inc/myuart.h"
#define GPGCON	(*(volatile unsigned char *)0x56000060)
#define GPGDAT	(*(volatile unsigned char *)0x56000064)
#define GPGUP	(*(volatile unsigned char *)0x56000068)
#pragma import(__use_no_semihosting_swi)  // ensure no functions that use semihosting 
#define MCP2510_Enable()		GPGDAT=GPGDAT&0xfffd
#define MCP2510_Disable()       GPGDAT=GPGDAT|0x0002

int main(void)
{
	int n;
	unsigned int id;
	int length;
	BOOL rxRTR, isExt;
	U8 data[8]={0,};

	ARMTargetInit();	//开发版初始化
  
	init_MCP2510(BandRate_250kbps);//可在该函数内设置成回环模式
                                  //从而只用一台设备完成实验
                                  
   /* while(1)                              
     {  GPGCON=0xfffffff7;
        GPGUP=0xffff; 
        GPGDAT=0xfffd;                         
        
        Uart_Printf(0,"waaaewe");
hudelay(100);
        GPGDAT=0xffff;
        Uart_Printf(0,"xcvvvv");
hudelay(100);}                          */
                                  
                                  
	canSetup();

	Uart_SendByte(0,0xa);//换行
	Uart_SendByte(0,0xd);//回车
    Uart_Printf(0,"\n\n+----------CAN TEST----------+\n\n");
	while(1)
	{
MCP2510_Disable();
hudelay(1000);
MCP2510_Enable();
		if(Uart_Poll(0)){	//串口收到数据,则发送到CAN总线
			//Uart_Printf(0,"hi ");
			
			
			Uart_Getch((char*)data,0,0);
			//Uart_Printf(0,"wewe");
			canWrite(0x7ff, data, 8, FALSE, FALSE);
			Uart_Printf(0,"send data:");
			//Uart_Printf(0,"id isjkkjk ");
			Uart_SendByte(0,*data);
			Uart_Printf(0,"\n");
		}else if((n=canPoll())!=-1){//CAN总线收到数据,则发送到串口
		    Uart_Printf(0,"receive data:");
			canRead(n, &id, data, &length,  &rxRTR, &isExt);
			Uart_SendByte(0,data[0]);	//显示采集的数据
			Uart_Printf(0,"\n");
            //Uart_Printf(0,"id is %x",id);
			if(data[0]=='\r')	//发送换行
				Uart_SendByte(0,'\n');
					
		}
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -