微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 基于51单片机can总线头文件定义

基于51单片机can总线头文件定义

时间:11-24 来源:互联网 点击:

#define IDADDR XBYTE[0xbf00] //74LS244地址,用于确定节点号

uchar data SJA_TXBuffer[13]={0x88,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33};
bitRX_OK=0;

void SJA_Init_Peli(void)
{
REG_MODE=0X01;
REG_CDR =0X80;
REG_IER =0X0D;
REG_AMR0=0XFF;
REG_AMR1=0XFF;
REG_AMR2=0XFF;
REG_AMR3=0XFF;

REG_ACR0=0X00;
REG_ACR1=0XFF;
REG_ACR2=IDADDR & 0x0f;
REG_ACR3=0X00;

REG_BTR0=0X40;
REG_BTR1=0X1C;
REG_OCR =0XAA;
REG_RBSA=0X00;
REG_TXERR=0X00;
REG_ECC =0X00;
REG_MODE=0X00;
}

void SJA_TX_Peli(void)
{
uchar a,i;
a=REG_SR;
if(a&0x10)
{
a=REG_SR;
}
if(!(a&0x08))
{
a=REG_SR;
}
if(!(a&0x04))
{
a=REG_SR;
}
SJA_PeliCANAdr=REG_TXB;
a=SJA_TXBuffer[0];
a&=0x0f;
a=a+4;
*SJA_PeliCANAdr=SJA_TXBuffer[0];
for(i=0;i{
SJA_PeliCANAdr++;
*SJA_PeliCANAdr=SJA_TXBuffer[i+1];
}
REG_CMR=0X01;
}
void SJA_RX_Peli(void)
{
uchar bdata a,b,i;
a=REG_SR;
if(a&0xC3)
{
if(a&0x80)
{
b=REG_IR;
REG_MODE=0X00;
return;
}
else
{
b=REG_IR;
if(b&0X08)
{
REG_CMR=0X0C;
return;
}
else
{
if(b&0X01)
{
SJA_PeliCANAdr=REG_TXB;
SJA_TXBuffer[0]=*SJA_PeliCANAdr;
a=SJA_TXBuffer[0];
a&=0x0f;
a=a+4;
for(i=0;i{
SJA_PeliCANAdr++;
SJA_TXBuffer[i+1]=*SJA_PeliCANAdr;
}
RX_OK=1;
REG_CMR=0X04;
}
a=REG_ALC;
a=REG_ECC;
return;
}
}
}
else
{
return;
}


}

void main(void)
{
uchar i=0;
SP=0x60;
SJA_Init_Peli();
SJA_TX_Peli();
while(i!=0XC8)
{
SJA_RX_Peli();
if(RX_OK)
{
i++;
RX_OK=0;
}
}
SJA_TX_Peli();
while(1);
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top