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

📄 example.c

📁 Simple FullCAN Reciver-Transmiter for LPC23xx
💻 C
字号:
/*****************************************************************************
 *
 *      Project:    Clock Example
 *      Name:       Example
 *      Filename:   Example.c
 *      Date:       06.04.2001
 *      Rights:     hitex-systementwicklung GmbH
 *                  Greschbachstr. 12
 *                  76229  Karlsruhe
 *
 ****************************************************************************/

/**************************** module example.c ******************************/
extern void vLCDInit (void);
extern void vLCDPutc (unsigned char c);
extern void vLCDPuts (unsigned char *sp);
unsigned char Message[16] = "LCD Test\n";
#include "lpc230x.h"

unsigned int *FullCANFilter;
unsigned  int *StandardFilter; 								//Declare pointers for the acceptence filter tables 
unsigned  int *GroupStdFilter; 		
unsigned  int *IndividualExtFilter;    
unsigned  int *GroupExtFilter;		

void FullCAN (void)__attribute__ ((interrupt ("IRQ")));

unsigned int *FullCANBuffer;	 

 
int main(void)
{
unsigned int  flasher;
    
unsigned int delay; //
	/* Reset all GPIO pins to default: primary function */
    PINSEL0 = 0x00000000;
    PINSEL1 = 0x00000000;
    PINSEL2 = 0x00000000;
    PINSEL3 = 0x00000000;
    PINSEL4 = 0x00000000;
    PINSEL5 = 0x00000000;
    PINSEL6 = 0x00000000;
    PINSEL7 = 0x00000000;
    PINSEL8 = 0x00000000;
    PINSEL9 = 0x00000000;
    PINSEL10 = 0x00000000;
    
    IODIR0 = 0x00000000;
    IODIR1 = 0x00000000;
	  IOSET0 = 0x00000000;
    IOSET1 = 0x00000000;
    
    FIO0DIR = 0x00000000;
    FIO1DIR = 0x00000000;
    FIO2DIR = 0x00000000;
    FIO3DIR = 0x00000000;
    FIO4DIR = 0x00000000;
    
    FIO0SET = 0x00000000;
    FIO1SET = 0x00000000;
    FIO2SET = 0x00000000;
    FIO3SET = 0x00000000;
    FIO4SET = 0x00000000;			
    FIO2DIR = 0x000000FF;
    FIO2MASK = 0xFFFFFF00; 		
   //vLCDInit();
  //vLCDPutc('T'); 
  // vLCDPuts(Message);
PINSEL0                 |=  0x5 | 0x2<<8|0x2<<10;
PCONP                   |=  0x1<<13 | 0x1<<14;
CAN2_MOD 	            |=  0x00000001;			//Set CAN controller into reset
CAN2_BTR 	            = 	0x0B | 0x05<<16 | 0x02<< 20;
CAN2_MOD 	            = 	0x00000000;			//Release CAN controller

CAN1_MOD 	           |= 	0x00000001;			//Set CAN controller into reset
CAN1_BTR 	            = 	0x0B | 0x05<<16 | 0x02<< 20;
			//enable interrupt

CAN_AFMR			=	0x00000003;						//Disable the Acceptance filters to allow setup of the table
FullCANFilter		=   (unsigned int *)0xE0038000;		//Pointer to Standard filter table
*FullCANFilter		=	0x10010802;
FullCANFilter++;
*FullCANFilter		=	0x08040808;                           //Note first entry disabled to keep an even number o entries in the table
FullCANFilter++;
*FullCANFilter		=	0x08100820;
FullCANFilter++;
*FullCANFilter		=	0x08400880;         

CAN_SFF_SA			=	0x00000010;			 			//Set start address of Standard table
CAN_SFF_GRP_SA		=	0x0000010;						//Set start address of Standard group table
CAN_EFF_SA			=	0x00000010;						//Set start address of Extended table
CAN_EFF_GRP_SA		=	0x00000010;						//Set start address of Extended group table
CAN_EOT     		=	0x00000010;						//Set end of table address
FCANIE              =   0x01;	     //
VICVectPriority23   = 	0x00000000;  					//select a priority slot for a given interrupt
VICVectAddr23 	    = 	(unsigned)FullCAN;				//pass the address of the IRQ into the VIC slot
VICIntEnable 	    = 	0x00800000;			
CAN_AFMR			=	0x00000004;						//Enable Acceptance filters
CAN1_MOD 			= 	0x00000000;						//Release CAN controller
CAN2_TFI1 	 	    =	0x00040000;			//Set DLC to 4 bytes 	

while(1)
{
    
    for(flasher =1;flasher<0x00000100;flasher = flasher <<1)
    {
      CAN2_TID1 		= 		flasher;			//Set address to 2 Standard Frame
      
       if(CAN2_SR & 0x00000004)					//See if Tx Buffer 1 is free
        {

          CAN2_TDA1		=		flasher;				//Copy A/D result into first four bytes
          CAN2_CMR 		= 		0x00000021;			//Transmit the message
        }
      
        for(delay = 0;delay<0xA0000;delay++)				  	       //simple delay loop
        {
          ;
        }
      }
    
}

}
volatile unsigned int offset;
unsigned int counter = 0;
void FullCAN (void)	  
{
counter = 0;
for(offset = 2;offset < 0x0008000;offset = offset<<1)
    {
             
      if(offset & FCANIC0)
      {
      FullCANBuffer =  (unsigned int)(0xE003801C + (counter*12));
      while(!(*FullCANBuffer & 0x03000000))                           //check the SEM bits to make sure the buffer is updated
        {
        ;
        }
      *FullCANBuffer = *FullCANBuffer & (~0x03000000);                  //Clear the SEm bits before reading the buffer
      FullCANBuffer = FullCANBuffer + (unsigned int)0x1;
      FIO2CLR               = 0x000000FF;
      FIO2SET               = *FullCANBuffer;
      FCANIC0 = FCANIC0 &(~offset);
      }
    counter++;
    }
    VICVectAddr 			= 	0x00000000;						         //Signal the end of interrupt
}

⌨️ 快捷键说明

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