main_ex1.c

来自「ATMEL的can实验联系测试程序1,发送程序1」· C语言 代码 · 共 89 行

C
89
字号
/*C**************************************************************************
* Main_ex1.c 
*----------------------------------------------------------------------------
* Copyright (c) 2002 Atmel.
*----------------------------------------------------------------------------
*----------------------------------------------------------------------------
* PURPOSE: 
* 
*****************************************************************************/

/*_____ I N C L U D E S ____________________________________________________*/
#include "REG51CC01.h"


void main(void)
{
  unsigned char message_object;
  unsigned char data_cpt;
  unsigned char can_data[8]= {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77};
  unsigned int  can_id_st =  /* To Do */

/*________________________________________*/
/*_____ CAN CONTROLLER CONFIGURATION _____*/
/*________________________________________*/

/* Reset de CAN controller */
  CANGCON = 0x01; 

/* Reset DPRAM of the CAN controller */
  for (message_object=0; message_object <15; message_object++)
  {
    CANPAGE = (message_object << 4); /* Select the message object */
    CANCONCH = 0x00;
    CANSTCH  = 0x00;
    CANIDT1 = 0x00;
    CANIDT2 = 0x00;
    CANIDT3 = 0x00;
    CANIDT4 = 0x00;
    CANIDT1 = 0x00;
    CANIDT2 = 0x00;
    CANIDT3 = 0x00;
    CANIDT4 = 0x00;
    for (data_cpt = 0; data_cpt <8; data_cpt++)
    {
      CANMSG = 0x00; /* This register is auto_incremented*/
    }
  }

/* Configure the bit timming */
  CANBT1 = /* To Do */
  CANBT2 = /* To Do */
  CANBT3 = /* To Do */
 
/* Enable the CAN controller */
  CANGCON = 0x02;

/*____________________________________________________________*/
/*_____ CONFIGURE THE MESSAGE OBJECT 1 TO SEND A MESSAGE _____*/
/*____________________________________________________________*/

  CANPAGE = (1 << 4); /* Select the message object 1 */

/* Load data to transmit */
  for (data_cpt = 0; data_cpt <8; data_cpt++)
  {
    CANMSG = can_data[data_cpt]; 
  }
  
/* Load identifier */
  CANIDT1 = (unsigned char)(can_id_st >> 3);
  CANIDT2 = (unsigned char)(can_id_st << 5);
  CANIDT3 = 0x00;
  CANIDT4 = 0x00;

/* load number of data */
	CANCONCH = 0x08;
 
  while(P3_3 !=0);

  CANCONCH |= 0x40;

  while((CANSTCH&0x40)!=0x40);
  CANCONCH = 0x00;
  
  while(1);
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?