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

📄 lpc2000_can_sys.c

📁 飞利浦LPC2000系列CAN控制器驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
* FILENAME:      LPC2000_CAN_SYS.C                                            *  
*                                                                             *
* VERSION:       V1.0                                                         *
*                                                                             *
* DESCRIPTION:   Philips LPC2000 CAN Controller Driver with SJA1000           *                     
*				 Demo by UART0 with KEIL MCB2100 Evaluation Board			  *
*				 Code runing indicate by LED4 with Timer1 interrupt			  *
*                UART0 tested with Receive "a" NOT LED1, Receive "b" NOT LED2 *
*                                                                             *
* TOOLS:         KEIL uVision3                                     			  *
*                ARM Development Suite ADS1.2								  *
*                KEIL MCB2100 Evaluation Board               				  *
*                                                                             *
* REVISION HISTORY                                                            *
* Version  Author           Date        Remarks								  *
* 1.0      Anthony Xie      10/10/2005    - -                                 *     
*******************************************************************************/

// -----------------------------------------------
// Project include files                                                     
// -----------------------------------------------
#include  "LPC2294.h"
#include  "config.h"
#include  ".\CAN\LPC2000_CAN.h"

//-----------------------------------------------
//Constant Definitions
//-----------------------------------------------
#define	  LED4CON	(1<<23)		// P1.23 control LED4
#define   LED3CON	(1<<22)		// P1.22 control LED3
#define	  LED2CON	(1<<21)		// P1.21 control LED2
#define   LED1CON	(1<<20)		// P1.20 control LED1


//---------------------------------------------
//Global Variable Definitions
//---------------------------------------------

	  //System Global Variable
UInt32 System_Counter,LED_Counter=0;
UInt8 LED_Flag=0;
UInt8 System_Status=0;

//---------------------------------------------
//* Functions
//---------------------------------------------
void init(void);
void delay(UInt32);
void __irq IRQ_Timer1(void);
void uart0_config(UInt32,UART0MODE);
void __irq IRQ_UART0(void);
void __irq IRQ_CAN1Tx(void);
void __irq IRQ_CAN2Rx(void);


//***************************************************************************
//* main()
//* Input(s): none.
//* Returns : none.
//* Description : main loop
//***************************************************************************
int  main(void)
{ 
  UInt32 i=0;
  plpc2000CANdriver_TXObj_t pCAN_Send_Data;
  plpc2000CANdriver_RXObj_t pCAN_Rcv_Data;
    
  delay(20);
  init();  

  Print_Chars_to_Screen( Demo_Start );

  for(;;)	
  {        

    if( LED_Flag == 0 ) IO1SET = LED4CON;	//Control LED4
    else IO1CLR = LED4CON;
    if( LED_Flag == 10) LED_Flag = 5;		// Solve ADS12 compiler problem, this condition will 
    										// never be met, and the two value can't be same

    switch( System_Status )
	  {
	    case 0:	    // wait input (1,2 choice) status
		  break;
		case 1:									   // "1" be pressed
		  lpc2000CANdriver_SetACFMode( LPC2000_ACC_BYPASS );
		  Print_Chars_to_Screen( Demo_Sent_Data );
		  Print_Chars_to_Screen( Data_Sent_Start_or_Not ); 
		  System_Status = 3;
		  break;
		case 2:									   // "2" be pressed
          lpc2000CANdriver_SetACFMode( LPC2000_ACC_ON );
		  Print_Chars_to_Screen( Demo_Sent_Data );
		  Print_Chars_to_Screen( Acceptance_Filter_Tables );
		  Print_Chars_to_Screen( Data_Sent_Start_or_Not ); 
		  System_Status = 3;
		  break;
		case 3:	   // wait input (y,n choice) status
		  break;
		case 5:	   // "y or Y" be pressed, 
		  pCAN_Send_Data = CAN_Send_Data;
          for( i=0;i<5;i++)
	        {
              Return_Value = lpc2000CANdriver_CertainTxBufTransmitMessage(LPC2000_CANCHANNEL_1,pCAN_Send_Data,LPC2000_TXB_1);

			  pCAN_Send_Data++;
		    }

		  System_Status = 0;
		  break;								
		case 7:	 // "N or n " be pressed
		  Print_Chars_to_Screen( Demo_Sent_Choice );
		  System_Status = 0;
		  break;
		default:
		  break;
	  }

    if( CAN_Rcv_Status == 1 ) //communication successed
	  {
          Print_Chars_to_Screen( Rcv_Data_OK );          
		  pCAN_Rcv_Data = CAN_Rcv_Data;	  // print to uart0 all data in Rcv_Buffer
		  for( i=0;i<CAN_Rcv_Data_Counter;i++)				  
		    {
			  Rcv_Data_Output_to_Screen( pCAN_Rcv_Data );
			  pCAN_Rcv_Data++; 
			}
		  CAN_Rcv_Data_Counter = 0;     // reset Rcv_Buffer, point to head, means empty it.
		  Print_Chars_to_Screen( Demo_Sent_Choice );

		  CAN_Rcv_Status = 0;
	  }


    if( CAN2Rx_Return_Message_Flag[0] != 0 ) // if one CAN2Rx interrupt happened
	  {										 // print massage of communication status
		
		for( i=1;i<10;i++)
		{
		  if( CAN2Rx_Return_Message_Flag[i] != 0)
		    {
              switch(i)
			    {
				  case 1: 
				    Print_Chars_to_Screen( CAN2Rx_Return_Message_EI );
				    Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );      
				    break;
 				  case 2: 
				    Print_Chars_to_Screen( CAN2Rx_Return_Message_DOI );
				    Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
					break;
				  case 3: 
				    Print_Chars_to_Screen( CAN2Rx_Return_Message_WUI );
				    Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
					break;
				  case 4: 
				    Print_Chars_to_Screen( CAN2Rx_Return_Message_EPI );
				    Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
					break;
				  case 5: 
				    Print_Chars_to_Screen( CAN2Rx_Return_Message_ALI );
				    Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
					break;
				  case 6: 
				    Print_Chars_to_Screen( CAN2Rx_Return_Message_BEI );
				    Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
					break;
				  default:
				    break;
				}
			  CAN2Rx_Return_Message_Flag[i]=0;			  
			}
		}

	    CAN2Rx_Return_Message_Flag[0] = 0;
	  }

    if( (Return_Value != 0) && (Return_Value != 5))	  // Report CAN error status
	  {
	    switch(Return_Value)
		  {
		    case 10:
			  Print_Chars_to_Screen( CAN_Error_10 );
			  Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
			  break;
		    case 30:
			  Print_Chars_to_Screen( CAN_Error_30 );
			  Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
			  break;
		    case 31:
			  Print_Chars_to_Screen( CAN_Error_31 );
			  Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
			  break;
		    case 40:
			  Print_Chars_to_Screen( CAN_Error_40 );
			  Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
			  break;
		    case 50:
			  Print_Chars_to_Screen( CAN_Error_50 );
			  Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
			  break;
		    case 60:
			  Print_Chars_to_Screen( CAN_Error_60 );
			  Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
			  break;
		    case 90:
			  Print_Chars_to_Screen( CAN_Error_90 );
			  Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
			  break;
		    case 100:
			  Print_Chars_to_Screen( CAN_Error_100 );
			  Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
			  break;
		    case 110:
			  Print_Chars_to_Screen( CAN_Error_110 );
			  Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
			  break;
		    case 120:
			  Print_Chars_to_Screen( CAN_Error_120 );
			  Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
			  break;
		    case 130:
			  Print_Chars_to_Screen( CAN_Error_130 );
			  Print_Chars_to_Screen( CAN_ERROR_STOP_DEMO );
			  break;
			default:
			  break;
		  }

		Return_Value = 0;
	  }
      
  }
   
  return(0);
}

                               
//***************************************************************************
//* init()
//* Input(s): none.
//* Returns : none.
//* Description : initialization each function
//***************************************************************************
void init(void)
{
  UART0MODE Uart0_Config;


//-----------------------------------------------
//Config GPIO
//-----------------------------------------------
  PINSEL0  = 0x00000000;		// All be GPIO, Note: 2 bits config 1 pin!
  PINSEL0 |= 0x00000005;		// P0.0-TxD0,P0.1-RxD0

  PINSEL1 |= 0x00000000;		// All be GPIO, Note: 2 bits config 1 pin!
  PINSEL1 |= 0x00014000;		// P0.23-RD2, P0.24-TD2
//  PINSEL1 |= 0x00004000;		// P0.23-RD2, only enable receive for CAN2
  PINSEL1 |= 0x00040000;        // P0.25-RD1, Note:needn't for Self-Testing, Even not connect RD1			   
 
   
								// P1.16-23, has been configed to GPIO in <startup.s>
  IO1DIR = 0x00FF0000;          // P1.16 - 23 output, other input, 
                                // 0000 0000 1111 1111 0000 0000 0000 0000
  IO1CLR = 0x00FF0000;          // Turn off LED1 - LED8


//-----------------------------------------------
//Config Timer1
//Fcclk = Fosc*4 = 12MHz*4 = 48MHz

⌨️ 快捷键说明

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