求助 C8051F500单片机CAN的初始化问题

2020-01-23 14:48发布

本人以前未接触过CAN,现要用的时候看了一堆英文资料也没大看明白。
   
单片机选择的是C8051F500 ,C8051F500单片机内嵌有BOSCH的CAN控制器,现请教怎么初始化CAN,
特别是屏蔽寄存器和滤波寄存器具体怎么配置去实现报文滤波。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
8条回答
l310091170
2020-01-24 01:04
回复【5楼】tracy2223  

我是新手,你看看下面的程序,希望你会受到启发。
-----------------------------------------------------------------------
// F500_Ports_SwitchLED.c


SBIT (LED, SFR_P1, 3);                 // LED == 1 means ON
SBIT (SW1, SFR_P1, 4);                 // SW1 == 0 means switch depressed



void OSCILLATOR_Init (void);
void PORT_Init (void);



void main (void)
{
   SFRPAGE = ACTIVE_PAGE;              // Set SFR Page for PCA0MD

   PCA0MD &= ~0x40;                    // Disable the watchdog timer

   PORT_Init ();                       // Initialize Port I/O
   OSCILLATOR_Init ();                 // Initialize Oscillator

   while (1)
   {
      if (SW1 == 0)                    // If switch depressed
      {
         LED = 1;                      // Turn on LED
      }
      else
      {
         LED = 0;                      // Else, turn it off
      }
   }                                   // end of while(1)
}                                      // end of main()

//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------



void OSCILLATOR_Init (void)
{
   U8 SFRPAGE_save = SFRPAGE;
   SFRPAGE = CONFIG_PAGE;

   OSCICN = 0x84;                      // Configure internal oscillator for
                                       // 24 MHz / 8

   SFRPAGE = ACTIVE_PAGE;

   RSTSRC = 0x04;                      // Enable missing clock detector

   SFRPAGE = SFRPAGE_save;
}


void PORT_Init (void)
{
   U8 SFRPAGE_save = SFRPAGE;
   SFRPAGE = CONFIG_PAGE;

   P1MDIN |= 0x08;                     // P1.3 is digital
   P1M

一周热门 更多>