SJA1000+C51
delay(100);
CAN_node_ID();
Rx_node_Num();
EXIT: return ;
}
/************************************************************************
*函数原型: bit Rx_node_Num( )
*参数说明: no
*返回值:
* 此函数可以根据用户需在更改和删除
*说明:配置CAN控制器接收缓冲器情况
************************************************************************/
void Rx_node_Num()
{ // 如果RX信息计数器为空则LED0亮
unsigned char temp_Num;
temp_Num = REG_Receive_Counter;
if(temp_Num == 0)
{
LED0 = OFF;
}
else LED0 = ON;
return ;
}
/************************************************************************
*函数原型: can_test( )
*参数说明: no
*返回值:
* 此函数可以根据用户需在更改和删除
*说明:只用于硬件测试,全部CAN配置在内,只用此函数只可测试节点情况
************************************************************************/
void can_test(void)
{
unsigned char temp_data;
temp_data = REG_SR;
if((temp_data & DOS_SR) == DOS_SR) //数据溢出状态
{
REG_CMD |= 0x0c; //clear over status and realve RX_FIFO
REG_CMD |= 0x0c;
}
if((temp_data & TBS_SR) == TBS_SR) //发送缓冲区状态 1释放
{
REG_RxBuffer0 = 0x88; //EFF 标准帧SFF,长度为8
// REG_RxBuffer1=0x00;
// REG_RxBuffer2=0x00;
// REG_RxBuffer3=0x00;
// REG_RxBuffer4=0x08; //ID.4-ID.0 and bit2~0 no use
REG_DataBuffer1 = x;
REG_DataBuffer2 = i;
REG_DataBuffer3 = a;
REG_DataBuffer4 = o;
REG_DataBuffer5 = z;
REG_DataBuffer6 = h;
REG_DataBuffer7 = a;
REG_DataBuffer8 = o;
}
CAN_cmd(TR_CMD); //TX request 请求
temp_data = REG_SR;
temp_data &= TBS_SR; //TX buffer status 发送状态
while(temp_data == TBS_SR) //检查是否发送完成
{
ecc = REG_ECC;
temp_data = REG_SR;
temp_data &= 0X20;
}
}
/************************************************************************
*函数原型: Rx_Data( )
*参数说明: no
*返回值:
* 设置不同的缓冲区需修改不同的接收缓冲变量
*说明: 定义了Rx_buffer缓冲区
************************************************************************/
void Rx_Data()
{
unsigned char temp_data;
temp_data = REG_SR;
F0 = 1;
if((temp_data & RBS_SR) == 0) //RBS Rx buffer status 1-RXFIFO have message
{
goto EXIT1;
}
Rx_buffer.dlen = REG_RxBuffer0; //node message
temp_data = Rx_buffer.dlen;
Rx_buffer.did1 = REG_RxBuffer1; //node message ID
Rx_buffer.did2 = REG_RxBuffer2;
Rx_buffer.did3 = REG_RxBuffer3;
Rx_buffer.did4 = REG_RxBuffer4;
temp_data = Rx_buffer.dlen;
if( (temp_data & 0x40) == 0x00)
{
Rx_buffer.ddata[0] = REG_DataBuffer1; //message data
Rx_buffer.ddata[1] = REG_DataBuffer2;
Rx_buffer.ddata[2] = REG_DataBuffer3;
Rx_buffer.ddata[3] = REG_DataBuffer4;
Rx_buffer.ddata[4] = REG_DataBuffer5;
Rx_buffer.ddata[5] = REG_DataBuffer6;
Rx_buffer.ddata[6] = REG_DataBuffer7;
Rx_buffer.ddata[7] = REG_DataBuffer8;
F0 = 0;
}
//F0 = 0; //realve Rx buffer succefe
CAN_cmd(RRB_CMD); //send realve commd to SJA1000
EXIT1: return;
}
/************************************************************************
*函数原型: bit CAN_node_ID( )
*参数说明: no
*返回值:
* 此函数可以根据用户需在更改
*说明:配置CAN控制器识别符ID,为了便于测试配置REG_CAN_TXBUF3为开关ID
************************************************************************/
void CAN_node_ID(void)
{
unsigned char idata temp_data;
P1 = 0xf8;
temp_data = P1;
temp_data = (temp_data >> 3);
if( (temp_data & 0x1F) > 0x09 )
{
temp_data = (temp_data & 0x1F) + 0x37;
}
else temp_data = (temp_data & 0x0F) + 0x30;
REG_TxBuffer0 = 0x80; //frame is EFF data leng is 0
REG_TxBuffer1 = 0x00;
REG_TxBuffer2 = 0x00;
REG_TxBuffer3 = temp_data;
REG_TxBuffer4 = 0x00; //ID.4-ID.0 and bit2~0 no use
}
/************************************************************************
*函数原型: Tx_data( )
*参数说明: no
*返回值:
* 此函数可以根据用户需在更改
*说明:由全局变量Tx_buffer作缓冲,接收CAN读出的信息.
************************************************************************/
void Tx_data()
{
unsigned char temp_data;
temp_data = REG_SR;
F0 = 1;
if( (temp_data & TCS_SR) == 0)
{
ERR_flag = no_TCS;
goto EXIT2;
}
if( (temp_data & TBS_SR)== TBS_SR ) //Tx buffer is empty?
{
REG_TxBuffer0 |= (Tx_buffer.dlen & 0x0F); //EFF 标准帧SFF,长度为8
SJA1000C5 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)