⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 can81c9x.c

📁 CAN总线传输及液晶显示文章
💻 C
字号:
//****************************************************************************
// @Module        Standalone Full-CAN Controller SAE 81C90/1
// @Filename      CAN80C9x.C
// @Project       Hands on Training for the kitCON CAN/LCD Module
//----------------------------------------------------------------------------
// @Controller    Siemens C16x
//
// @Compiler      Tasking C166 V5.0
//                Keil C166 V3.00
//
// @Author        Michael Knese
//
// @Description   This file contains all functions that use the CAN Controller 
//                SAE 81C90 and SAE 81C91 of the kitCON CAN-LCD Module of 
//                PHYTEC
//                CAN Controller Number 0 = SAE 81C91
//                CAN Controller Number 1 = SAE 81C90
//
//----------------------------------------------------------------------------
// @Date          12/08/98 12:44:55 PM
//
//****************************************************************************

//****************************************************************************
// @Project Includes
//****************************************************************************

#include "MAIN.H"


// USER CODE BEGIN (CAN81C9x_General,1)

// USER CODE END


//***************************************************************************
// @Global Variables
//***************************************************************************

// USER CODE BEGIN (CAN81C9x_General,2)

// USER CODE END




//****************************************************************************
// @Function      void CAN81C9x_vInit90(void)
//
//----------------------------------------------------------------------------
// @Description   This function initializes the CAN 81c90 component. It effects all
//                necessary configurations of the SFR, depending on the selected
//                operating mode. 
//
//----------------------------------------------------------------------------
// @Returnvalue   none
//
//----------------------------------------------------------------------------
// @Parameters    none
//
//----------------------------------------------------------------------------
// @Date          11/16/98 12:44:55 PM
//
//****************************************************************************

void CAN81C9x_vInit90(void)
{

  //  -------------- CAN Mode/Status Register ---------------
  //  start the initialization of the CAN Module
  CAN_CON[1].MOD   = 0x001;

  //  -------------- Output-Control Register ----------------
  //  Output Mode:  Normal Mode
  //  TX0: The Output is driven directly with CAN data
  //       The high and low side transistor T0P/T0N are enable
  //  TX1: The Output is driven directly with CAN data
  //       The high and low side transistor T1P/T1N are enable
  CAN_CON[1].OC    = 0x0D8;

  //  --------------- CAN Control Register ------------------
  CAN_CON[1].CTRL  = 0x000;

  //  ---------------- Interrupt Register -------------------
  CAN_CON[1].INT   = 0x000;  //reset all interrupt request bits
  CAN_CON[1].IMSK  = 0x000;  //no interrupts (Interrupt mask register) 
  
  CAN_CON[1].RRR1  = 0x000;  //reset receive-Ready Register
  CAN_CON[1].RRR2  = 0x000;  //        -"-
  CAN_CON[1].RIMR1 = 0x000;  //disable all receive Bits (Receive-Interrupt -Mask Register)
  CAN_CON[1].RIMR2 = 0x000;

  ///  ------------ Bit Timing Register ---------------------
  /// baudrate =  100.000 KBaud
  /// there are 5 time quanta before sample point
  /// there are 4 time quanta after sample point
  /// the (re)synchronization jump width is 2 time quanta 
  CAN_CON[1].BL1   = 0x034;
  CAN_CON[1].BL2   = 0x041;
  CAN_CON[1].BRPR  = 0x009;


  //  ------------- Port Control Register -------------------
  CAN_CON[1].Port[0].PDR = 0x0FF;  //Port Direction Register (direction is output)
  CAN_CON[1].Port[0].LR  = 0x0FF;  //Port Latch Register ()



  //  ================== Descriptor Registers ===============

  //  Message-Object 0
  CAN_CON[1].DR[0].H  = 0;
  CAN_CON[1].DR[0].L  = 0;

  //  Message-Object 1
  //   This message operates as a data frame
  //   Identifier = 0x7
  CAN_CON[1].DR[1].H  = 0;	      //
  CAN_CON[1].DR[1].L  = 0x0E1;        // 

  CAN_CON[1].MsgObj[1].Data[7] = 0xAA;   // set data byte 7
  CAN_CON[1].MsgObj[1].Data[6] = 0x11;   // set data byte 6
  CAN_CON[1].MsgObj[1].Data[5] = 0x22;   // set data byte 5
  CAN_CON[1].MsgObj[1].Data[4] = 0x33;   // set data byte 4
  CAN_CON[1].MsgObj[1].Data[3] = 0x44;   // set data byte 3
  CAN_CON[1].MsgObj[1].Data[2] = 0x55;   // set data byte 2
  CAN_CON[1].MsgObj[1].Data[1] = 0x66;   // set data byte 1
  CAN_CON[1].MsgObj[1].Data[0] = 0x77;   // set data byte 0


  //  Message-Object 2-15
  CAN_CON[1].DR[2].H  = 0;
  CAN_CON[1].DR[2].L  = 0;

  CAN_CON[1].DR[3].H  = 0;
  CAN_CON[1].DR[3].L  = 0;

  CAN_CON[1].DR[4].H  = 0;
  CAN_CON[1].DR[4].L  = 0;
		  
  CAN_CON[1].DR[5].H  = 0;
  CAN_CON[1].DR[5].L  = 0;

  CAN_CON[1].DR[6].H  = 0;
  CAN_CON[1].DR[6].L  = 0;
     
  CAN_CON[1].DR[7].H  = 0;
  CAN_CON[1].DR[7].L  = 0;

  CAN_CON[1].DR[8].H  = 0;
  CAN_CON[1].DR[8].L  = 0;

  CAN_CON[1].DR[9].H  = 0;
  CAN_CON[1].DR[9].L  = 0;

  CAN_CON[1].DR[10].H  = 0;
  CAN_CON[1].DR[10].L  = 0;

  CAN_CON[1].DR[11].H  = 0;
  CAN_CON[1].DR[11].L  = 0;

  CAN_CON[1].DR[12].H  = 0;
  CAN_CON[1].DR[12].L  = 0;

  CAN_CON[1].DR[13].H  = 0;
  CAN_CON[1].DR[13].L  = 0;

  CAN_CON[1].DR[14].H  = 0;
  CAN_CON[1].DR[14].L  = 0;

  CAN_CON[1].DR[15].H  = 0;
  CAN_CON[1].DR[15].L  = 0;


  /// ------------ CAN Control/Status Register --------------
  //  reset INIT
  //  ...
  CAN_CON[1].MOD       = 0x000;



  // USER CODE BEGIN (CAN81C9x_Init90,1)

  // USER CODE END

}





//****************************************************************************
// @Function      void CAN81C9x_vInit91(void)
//
//----------------------------------------------------------------------------
// @Description   This function initializes the CAN 81C91 component. It effects all
//                necessary configurations of the SFR, depending on the selected
//                operating mode. 
//
//----------------------------------------------------------------------------
// @Returnvalue   none
//
//----------------------------------------------------------------------------
// @Parameters    none
//
//----------------------------------------------------------------------------
// @Date          11/16/98 12:44:55 PM
//
//****************************************************************************

void CAN81C9x_vInit91(void)
{

  //  -------------- CAN Mode/Status Register ---------------
  //  start the initialization of the CAN Module
  CAN_CON[0].MOD   = 0x001;

  //  -------------- Output-Control Register ----------------
  //  Output Mode:  Normal Mode
  //  TX0: The Output is driven directly with CAN data
  //       The high and low side transistor T0P/T0N are enable
  //  TX1: The Output is driven directly with CAN data
  //       The high and low side transistor T1P/T1N are enable
  CAN_CON[0].OC    = 0x0D8;

  //  --------------- CAN Control Register ------------------
  CAN_CON[0].CTRL  = 0x000;

  //  ---------------- Interrupt Register -------------------
  CAN_CON[0].INT   = 0x000;  //reset all interrupt request bits
  CAN_CON[0].IMSK  = 0x001;  //enable Receive Interrupt (Interrupt mask register)    <====

  CAN_CON[0].RRR1  = 0x000;  //reset receive-Ready Register
  CAN_CON[0].RRR2  = 0x000;  //        -"-
  CAN_CON[0].RIMR1 = 0x002;  //enable receive Bit Message 1 (Receive-Interrupt-Mask Register)
  CAN_CON[0].RIMR2 = 0x000;

  ///  ------------ Bit Timing Register ---------------------
  /// baudrate =  100.000 KBaud
  /// there are 5 time quanta before sample point
  /// there are 4 time quanta after sample point
  /// the (re)synchronization jump width is 2 time quanta 
  CAN_CON[0].BL1   = 0x034;
  CAN_CON[0].BL2   = 0x041;
  CAN_CON[0].BRPR  = 0x009;

  

  //  ================== Descriptor Registers ===============
 
  //  Message-Object 0
  CAN_CON[0].DR[0].H = 0;
  CAN_CON[0].DR[0].L = 0;

  //  Message-Object 1
  //   This message operates as a data frame
  //   Identifier = 0x7
  CAN_CON[0].DR[1].H = 0;
  CAN_CON[0].DR[1].L = 0x0E8;  




  //  Message-Object 2-15
  CAN_CON[0].DR[2].H = 0;
  CAN_CON[0].DR[2].L = 0;

  CAN_CON[0].DR[3].H = 0;
  CAN_CON[0].DR[3].L = 0;

  CAN_CON[0].DR[4].H = 0;
  CAN_CON[0].DR[4].L = 0;

  CAN_CON[0].DR[5].H = 0;
  CAN_CON[0].DR[5].L = 0;

  CAN_CON[0].DR[6].H = 0;
  CAN_CON[0].DR[6].L = 0;
     
  CAN_CON[0].DR[7].H = 0;
  CAN_CON[0].DR[7].L = 0;
		 
  CAN_CON[0].DR[8].H = 0;
  CAN_CON[0].DR[8].L = 0;

  CAN_CON[0].DR[9].H = 0;
  CAN_CON[0].DR[9].L = 0;

  CAN_CON[0].DR[10].H = 0;
  CAN_CON[0].DR[10].L = 0;

  CAN_CON[0].DR[11].H = 0;
  CAN_CON[0].DR[11].L = 0;

  CAN_CON[0].DR[12].H = 0;
  CAN_CON[0].DR[12].L = 0;

  CAN_CON[0].DR[13].H = 0;
  CAN_CON[0].DR[13].L = 0;

  CAN_CON[0].DR[14].H = 0;
  CAN_CON[0].DR[14].L = 0;

  CAN_CON[0].DR[15].H = 0;
  CAN_CON[0].DR[15].L = 0;


  /// ------------ CAN Control/Status Register --------------
  //  reset INIT
  //  ...
  CAN_CON[0].MOD      = 0x000;




  // USER CODE BEGIN (CAN81C9x_Init91,1)

  // USER CODE END

}





//****************************************************************************
// @Function      void CAN81C9x_vInit(void)
//
//----------------------------------------------------------------------------
// @Description   This function initializes the kitCON CAN component. It effects all
//                necessary configurations of the SFR, depending on the selected
//                operating mode. The configuration determines whether the CAN
//                interrupts are to be released, and the priority of the 
//                released interrupt.
//
//----------------------------------------------------------------------------
// @Returnvalue   none
//
//----------------------------------------------------------------------------
// @Parameters    none
//
//----------------------------------------------------------------------------
// @Date          12/7/98 5:47:05 PM
//
//****************************************************************************

void CAN81C9x_vInit(void)
{

 // initializes the CAN peripheral 81C90
  CAN81C9x_vInit90();

  // initializes the CAN peripheral 81C91
  CAN81C9x_vInit91();



  // USER CODE BEGIN (CAN81C9x_Init,1)

  // USER CODE END

}



//****************************************************************************
// @Function      void CAN_vTransmit(ubyte ObjNr)
//
//----------------------------------------------------------------------------
// @Description   This function triggers the CAN controller to send the 
//                selected message.
//                If the selected message object operates as a DATA FRAME then 
//                this function triggers the sending of a data frame.
//                If however the selected message object operates as a REMOTE 
//                FRAME this function triggers the sending of a remote frame.
//
//----------------------------------------------------------------------------
// @Returnvalue   none
//
//----------------------------------------------------------------------------
// @Parameters    Number of the CAN - Controller (0-1)
// @Parameters    Number of the message object to be sent (0-15)
//
//----------------------------------------------------------------------------
// @Date          12/7/98 5:47:05 PM
//
//****************************************************************************

void CAN81C9x_vTransmit(ubyte ConNr, ubyte ObjNr)
{
  uword uwTRS;

  uwTRS = 0x1 << ObjNr;

  CAN_CON[ConNr].TRSR2 = (uwTRS >> 8);
  CAN_CON[ConNr].TRSR1 = (uwTRS & 0x00FF);

}


⌨️ 快捷键说明

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