main_ex4.c

来自「canbus分析仪使用说明,很用用的,快来看吧」· C语言 代码 · 共 118 行

C
118
字号
/*C**************************************************************************
* Main_ex4.c 
*----------------------------------------------------------------------------
* Copyright (c) 2002 Atmel.
*----------------------------------------------------------------------------
*----------------------------------------------------------------------------
* PURPOSE: 
* The goal of this exercice is to learn How to use the CAN_lib with interrupt.
* 
*****************************************************************************/

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

#define BRP_100k    0x05
#define SJW_100k    0x00
#define PRS_100k    0x01
#define PHS2_100k   0x03
#define PHS1_100k   0x02

can_data_t data_temp;
can_msg_t can_temp;


void main(void)
{

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

  CAN_CONTROLLER_RESET; 
  RazAllMailbox();
  CanSetBRP  (BRP_100k);
  CanSetSJW  (SJW_100k);
  CanSetPRS  (PRS_100k);
  CanSetPHS2 (PHS2_100k);
  CanSetPHS1 (PHS1_100k);
  CAN_CONTROLLER_ENABLE;

  pt_st_can_rx = &can_temp;
  can_temp.pt_donne = data_temp;

/*_______________________________________________________________*/
/*_____ CONFIGURE THE MESSAGE OBJECT 0 TO RECEIVE A MESSAGE _____*/
/*_______________________________________________________________*/
  CAN_SET_CHANNEL(CHANNEL_0);
  conf_rx = CONF_NOBUFFER;
  ConfChannel_Rx();
  CAN_CHANNEL_IT_ENABLE(CHANNEL_0);

  CAN_TX_IT_ENABLE;
  CAN_RX_IT_ENABLE;
  CAN_IT_ENABLE;
  EA = 1;

  while(1);
}

/*F**************************************************************************
* FUNCTION_NAME: CAN interrupt declaration                                              
******************************************************************************/
Interrupt(it_7(void), 7)
{
  fct_can_it();
}

/****************************************************************************
* FUNCTION_NAME: can_fct_it_txok                                                
*----------------------------------------------------------------------------
* FUNCTION_AUTHOR: BERTHY J.S.                                              
* FUNCTION_DATE  :                                                  
*----------------------------------------------------------------------------
* FUNCTION_PURPOSE:                                   
* FUNCTION_INPUTS :                                                         
* FUNCTION_OUTPUTS:                                                         
******************************************************************************
* NOTE:                                                                      
******************************************************************************/
void can_fct_it_txok (void)
{
  while(1);
}

/****************************************************************************
* FUNCTION_NAME: can_fct_it_rxok                                                
*----------------------------------------------------------------------------
* FUNCTION_AUTHOR: BERTHY J.S.                                              
* FUNCTION_DATE  :                                                  
*----------------------------------------------------------------------------
* FUNCTION_PURPOSE:                                   
* FUNCTION_INPUTS :                                                         
* FUNCTION_OUTPUTS:                                                         
******************************************************************************
* NOTE:                                                                      
******************************************************************************/
void can_fct_it_rxok (void)
{
  ReadCanMsg(CHANNEL_DISABLE);
  CANSTCH = 0x00;
	/*____________________________________________________________*/
	/*_____ CONFIGURE THE MESSAGE OBJECT 1 TO SEND A MESSAGE _____*/
	/*____________________________________________________________*/
  CAN_SET_CHANNEL(CHANNEL_1); /* CANPAGE on CHANNEL 1*/

  can_tx_id     = pt_st_can_rx->id;
  conf_tx       = pt_st_can_rx->ctrl & 0x08;
  pt_candata_tx = pt_st_can_rx->pt_donne;
  CAN_CHANNEL_IT_ENABLE(CHANNEL_1);

  SendCanMsg();

}


⌨️ 快捷键说明

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