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

📄 elinmint.ex.txt

📁 这个是我在microchip公司的网站下载的PIC18系列单片的一些驱动程序
💻 TXT
字号:
#include "ELINMInt.h"

void InterruptVectorHigh(void);                                         // prototype of the routines used in this test
void InterruptVectorLow(void);
void InterruptHandler(void);
void main(void);

BYTE my_msg[8];                                                         // message buffer, used for tests

/*********************************************************************
 * Function:        void Main(void)
 *
 * PreCondition:
 *
 * Input:

 * Output:
 *
 * Side Effects:
 *
 * Stack Requirements:
 *
 * Overview:	Main function of the LIN Master Test Firmware
 *
 ********************************************************************/

void main(void)
{
 char leds;
 unsigned int mydelay;
 BYTE *pt;
 BYTE ErrorCode;
 BYTE ErrorTag;
 BYTE Tag;
 BYTE rxtag;

 mydelay=2000;                                                          // initialize the delay variable
 TRISC=0x9F;  								// init serial pins - TX and control (LIN driver)
 PORTCbits.RC5=0;							// negative edge (initial) pulse in the control
 if((ErrorCode=mELINMIntInitialize())==0)				// initialize Enhanced USART and LIN
 {
                                                                        // initialization error handling
 }
 T0CON=0xC8;								// initialize TIMER0
 INTCON_TMR0IE=1;							// enable timer0 int.
 INTCON_PEIE=1;								// enable ints.
 PORTCbits.RC5=1;							// positive edge pulse in the control pin (LIN Driver) 
 INTCON_GIE=1;
 while(mydelay--)							// initial delay -> necessary to MCP201.(Data Sheet - param. Tcsor)
  ;
 while(1)                                                               // run forever
 {
  Tag=0;                                                                // init Tag 
  mydelay=600;
  while(mydelay--)							// give a delay between messages, to make scope visalization easier
   ;

//*****************************************************
// First receive a single message using fixed value tag
// checking for the reception of that specific message
//*****************************************************

  while(mELINMIntRXBufferAvailable()==0)				// if there is no RX buffer available wait
   ;
  mELINMIntReceiveMessage(5,0x01,2);					// request data using tag=5 (message number), ID=0x01, size=2
  while(mELINMIntMessageReceived(5)==0)					// wait until the message is received
   ;
  if((ErrorCode=mELINMIntRXStatus(5)))        				// check if an RX error was detected
  {
                                                                        // error handling - to be added at this point by
   leds++;                                                              // application
  }
  else                                                                  // otherwise (no error)
  {
   pt=mELINMIntGetRXPointer(5); 					// get the data pointer
   my_msg[0]=*pt;							// read the message
   pt++;
   my_msg[1]=*pt;
                                                                        // received message handling - to be added at this point by
                                                                        // the application

  } // else

  mydelay=600;
  while(mydelay--)                                                      // give another delay
   ;

//*****************************************************
// Send a single message using fixed value tag
// checking for the transmission of that specific message
//*****************************************************

  while(mELINMIntTXBufferAvailable()==0)				// Wait TX buffer available
   ;
  pt= mELINMIntGetTXPointer(3);						// get the available pointer and tag it's message as 3
  *pt=my_msg[0];						        // insert data
  pt++;
  *pt=0;
  mELINMIntSendMessage(3,0x04,2);			                // send message
  while(mELINMIntMessageSent(3)==0)                                     // wait until transmission message #3 completes
   ;                                                                    // the application
  if((ErrorCode=mELINMIntTXStatus(3)))      				// check if an TX error was detected (!=0)
  {
                                                                        // error handling - to be added at this point by
   leds++;                                                              // application                                                                        // the application
  }

  mydelay=600;
  while(mydelay--)                                                      // give another delay
   ;

//*****************************************************
// Check for Sleep Time-Out and wake-up if necessary
//*****************************************************

  if(mELINMIntSleepTimeOut())                                           // if timeout set (more than 25000 bit-time
  {                                                                     // of silence in the BUS)
   mELINMIntSendWakeUPSignal();                                         // send wake-up signal to the slaves
                                                                        // add application code here
  }

//*****************************************************
// Check for Wake-Up Signal sent by slave
//*****************************************************

  if(mELINMIntCheckWakeUPReceived())                                    // check for Wake-Up signals received
  {
   if(mELINMIntSleepTimeOut())                                          // if timeout already set (more than 25000 bit-time)
   {                                                                    // of silence in the BUS

   }
   else                                                                 // if no timeout something unexpected happened, process
   {

   }
  }
 } // while (1)
} // void main(void)



//*****************************************************************************
// High priority interrupt vector
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh(void)
{
 _asm
 bra InterruptHandler // jump to interrupt routine
 _endasm
}
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorLow(void)
{
 _asm
 bra InterruptHandler // jump to interrupt routine
 _endasm


}

/*********************************************************************
 * Function:    void InterruptHandler(void)
 *
 * PreCondition:
 *
 * Input:

 * Output:
 *
 * Side Effects:
 *
 * Stack Requirements:
 *
 * Overview:	High priority interrupt routine
 *
 ********************************************************************/
#pragma code
#pragma interrupt InterruptHandler
void InterruptHandler(void)
{
 if(INTCON_TMR0IF)
  ELINMIntHandler();	                                                // process LIN int. based protocol
 TMR0L|=0x80;                                                           // timer0 int. every 128 counts - 128 instructions
                                                                        // time as timer0 is not using any prescaler (1:1)
 INTCON_TMR0IF=0;       						// reset int0 flag

}

⌨️ 快捷键说明

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