原创 模拟并口时序读写配置SJA1000 曙光单片机_现场总线CANBus_新浪博客
原创 模拟并口时序读写配置SJA1000 曙光单片机(2010-01-23 21:51:07)

原创,转载请注明出处,仅供CAN总线学习爱好者,交流学习!!
unsigned int Read_SJA1000(unsigned char address)
{
 unsigned char data;
 ALE=0;                         //ALE_off;
    WR=1;                       //WR_on;
    RD=1;                       //RD_on;
    CS=1;   
     ALE=1;
            delay1();    
  InitIOAOUT();
    *P_IOA_Data=address;         //输出数据的地址
             delay1();//asm("nop");                 //delay5us(1); 
     ALE=0;
             delay1();
     CS=0;                      //CAN_cs_off;
             delay1();
     RD=0;                       //RD_off;
             delay2();
     //asm("nop");                 //delay5us(2);    
    InitIOAIN();
    data=*P_IOA_Data;
          delay1();//asm("nop");                 //delay5us(1);
    RD=1;                       //RD_on;
             delay1();
    CS=1;
    ALE=1;                      //CAN_cs_on;
  return data;
}


void CAN_Init()
unsigned char i_temp=0,j_temp=0;
   //CLI();
   //asm("irq off");
   CS=0;
   Read_SJA1000(REG_INTERRUPT);                  //读中断寄存器,xx中断位
   Write_SJA1000(REG_CONTROL,0x01);           
   while(!(Read_SJA1000(REG_CONTROL)&0x01))     //保证进入复位模式,bit0.0不为1,再写CAN_MOD 
   {Write_SJA1000(REG_CONTROL,0x01);}
   Write_SJA1000(REG_CDR,0x88);           //配置时钟分频寄存器-Pelican,CBP=0,输出频率2MHZ
                                                           //关闭TX1中断与时钟输出 //测试CLOCKOUT的频率信号   
   Write_SJA1000(REG_AMR1,0x00);          //配置验收屏蔽AMR0=0FFH
   Write_SJA1000(REG_AMR2,0xff);          //配置验收屏蔽AMR1=000H
   Write_SJA1000(REG_AMR3,0x00);          //配置验收屏蔽AMR2=0FFH
   Write_SJA1000(REG_AMR4,0xff);          //配置验收屏蔽AMR3=000H
   Write_SJA1000(REG_ACR1,0x00);          //配置验收代码ACR1=0:广播
   Write_SJA1000(REG_ACR2,0x55);
   Write_SJA1000(REG_ACR3,0x03);          //配置验收代码ACR3=地址
   Write_SJA1000(REG_ACR4,0x55);
   Write_SJA1000(REG_BTR0,0x03);             //配置总线定时20kbps(18,1c) 24kbps(24,15) 30kbps(0d,1f) 40kbps(87,ff)50kbps(09,1c) 125kbps(03,1C) 250KBPS(01,1C)
   Write_SJA1000(REG_BTR1,0x1c);                            //500K(00,1C) 800K(00,16)
   Write_SJA1000(REG_OCR,0x1a);              //配置输出控制
   Write_SJA1000(REG_ERRLIMIT,0xff);         //配置错误报警限制为255
   Write_SJA1000(REG_INTENABLE,0x01);        //配置SJA1000中断-错误报警/发送/接收中断 
   do
   {
     Write_SJA1000(REG_CONTROL,0x00);
                                          //进入工作模式双滤波
   while(Read_SJA1000(REG_CONTROL));         // 确认复位标志是否被删除   
   //SEI();
  // __asm("irq on");
}

经典原创平台,两种can控制器,融于一体!!

我们一直致力于现场总线CAN的应用与推广,相信专注的力量!!

MSG-3C CAN总线开发板:

MSG-2C CAN总线开发学习板:

 

已投稿到:
郑重声明:资讯 【原创 模拟并口时序读写配置SJA1000 曙光单片机_现场总线CANBus_新浪博客】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——