字号:大中小
订阅
调试好的
can
总线程序(
c
语言)
//**********
程序功能
************************************************
//
节点
1
向
CAN
节点
2
发送数据
,
数据的头两个字节分别是
:
节点
1
的
ID
和要求节点
2
回复的数据长度
//
节点
2
收到节点
1
的信息后
,
立即按照节点
1
的要求回复数据
#
i nclude
#
i nclude
//SJA
存储器定义头文件
#
i nclude
//SJA
子程序文件
#
i nclude
//
显示头文件
#
i nclude
//
字符串函数
//***************************
头文件
***************************************************//
void Init_Cpu(void);
//
初始化单片机
void Sja_1000_Init(void);
//
初始化
SIA
//************************************************************************************
bit s;
//
配置
sja
标志
bit flag_send;
//
发送命令标志
unsigned char data a[5]={0x05,0x05,0x05,0x05,0x05}; //
显示
"5"
unsigned char b[5]={0x12,0x12,0x12,0x12,0x12};
//
显示
"p"
unsigned char c[5]={0x01,0x01,0x01,0x01,0x01};
//
显示
"1"
unsigned char data
send_data[10],rcv_data[10];
//
发送和接收数组
unsigned char bdata flag_init;
//
保存中断寄存器值
unsigned int count_k;
//
延时记数用
sbit rcv_flag=flag_init^0;
//
接收中断标志
sbit err_flag=flag_init^2;
//
错误中断标志
//***********************************************************************************//
void main(void)
{
s=0;
//
配置
sja1000
出现错误时
,
重新初始化
do{
Sja_1000_Init();
}while(s!=0);
Init_Cpu();
//initialize mcu
flag_init=0x00;
//
保存中断寄存器值清零
while(1)
{
if(rcv_flag)
//if there is receive interrupt
{
rcv_flag=0;
//
接收标志位清零
BCAN_DATA_RECEIVE(rcv_data);
//
接收数据