CAN BOARD TO BOARD COMMUCTION
CAN BOARD TO BOARD COMMUCTION
CODE FOR RECIVER BOARD
#include "prototype.h"
unsigned int MSG[4];
/* CAN TEST AT STARTING */
unsigned char can_test(void)
{
while(!(RX_in_CAN1()==2));
clear_lcd();
lcd_str("IGNITION ON");
delay(4000);
if(RX_in_CAN1()==3)
{
clear_lcd();
lcd_str("BRAKE TEST PASS");
delay(3000);
unsigned char can_test(void)
{
while(!(RX_in_CAN1()==2));
clear_lcd();
lcd_str("IGNITION ON");
delay(4000);
if(RX_in_CAN1()==3)
{
clear_lcd();
lcd_str("BRAKE TEST PASS");
delay(3000);
clear_lcd();
lcd_str("SEAT BELT PASS");
delay(3000);
return 1;
}
else
{
lcd_cmd(0x80);
delay(1000);
lcd_str("Chk BELT & brk");
lcd_str("SEAT BELT PASS");
delay(3000);
return 1;
}
else
{
lcd_cmd(0x80);
delay(1000);
lcd_str("Chk BELT & brk");
delay(3000);
return 0;
}
}
return 0;
}
}
void CAN_init(void)
{
VPBDIV = 0x02; // 30MHZ
PINSEL1 |= (1<<22)|(1<<24)|(1<<26)|(1<<28)|(1<<18)|(1<<16)|(1<<14);//0x15454000;/*CAN1 intialization*/
C1MOD=1 << 0; /*Reset CAN1 controller*/
C1BTR=1<<20 | 1<<19 | 1<< 18 | 29; //0x001C001D;/*Set baud Rate for CAN*/
C1MOD=0; /*Enable CAN1 controller*/
{
VPBDIV = 0x02; // 30MHZ
PINSEL1 |= (1<<22)|(1<<24)|(1<<26)|(1<<28)|(1<<18)|(1<<16)|(1<<14);//0x15454000;/*CAN1 intialization*/
C1MOD=1 << 0; /*Reset CAN1 controller*/
C1BTR=1<<20 | 1<<19 | 1<< 18 | 29; //0x001C001D;/*Set baud Rate for CAN*/
C1MOD=0; /*Enable CAN1 controller*/
}
/******************************************************/
unsigned int RX_in_CAN1(void)
{
while((C1SR&0X01));
MSG[0]=C1RID; //The 11-bit Identifier field of the current received message.
MSG[1]=C1RDA; // FIRST WORD OF DATA
MSG[2]=C1RDB; //SECOND WORD OF DATA
MSG[3]=C1RFS; // if bit10 is set, this msg was accepted in AF bypass mode
C1CMR= (1 << 2); // Release receive buffer
return MSG[1];
MSG[1]=C1RDA; // FIRST WORD OF DATA
MSG[2]=C1RDB; //SECOND WORD OF DATA
MSG[3]=C1RFS; // if bit10 is set, this msg was accepted in AF bypass mode
C1CMR= (1 << 2); // Release receive buffer
return MSG[1];
}
CODE FOR PROTYPE
#include<lpc21xx.h>
void delay(int);
void lcd_init(void);
void lcd_cmd(char);
void lcd_data(char);
void lcd_str(char *);
void lcd_num(unsigned int);
void clear_lcd(void);
void delay(int);
void lcd_init(void);
void lcd_cmd(char);
void lcd_data(char);
void lcd_str(char *);
void lcd_num(unsigned int);
void clear_lcd(void);
#define RS (1<<10)
#define RW (1<<12)
#define EN (1<<13)
#define DATA (0xff << 15)
#define LCD (EN |RW |RS|DATA)
#define RW (1<<12)
#define EN (1<<13)
#define DATA (0xff << 15)
#define LCD (EN |RW |RS|DATA)
void CAN_init(void);
unsigned int RX_in_CAN1(void);
unsigned char can_test(void);
unsigned int RX_in_CAN1(void);
unsigned char can_test(void);
CODE FOR MAIN
#include "prototype.h"
unsigned char BYTE[9];
unsigned char BYTE[9];
int main()
{
unsigned char res;
lcd_init();
CAN_init();
clear_lcd();
lcd_str("CAN TEST CODE Rx");
delay(2000);
clear_lcd();
//delay(1000);
TEST:
res = can_test();
if (res!=1)
goto TEST;
delay(2000);
while(1)
{
clear_lcd();
lcd_str(" VEHICLE ON");
delay(1000);
}
}// end of main
{
unsigned char res;
lcd_init();
CAN_init();
clear_lcd();
lcd_str("CAN TEST CODE Rx");
delay(2000);
clear_lcd();
//delay(1000);
TEST:
res = can_test();
if (res!=1)
goto TEST;
delay(2000);
while(1)
{
clear_lcd();
lcd_str(" VEHICLE ON");
delay(1000);
}
}// end of main
CODE FOR TX BOARD
CHECK LCD FUNCTION IN AUTOMOTIVE CAN BLOG
CODE FOR TX CAN
#include "prototype.h"
unsigned int MSG[4];
/* CAN TEST AT STARTING */
void can_test(void)
{
unsigned int a,b,key;
test:
lcd_str("TURN ON IGNITION");
delay(2000);
key = IOPIN1;
key = (1<<25) & key; // port po.5 has to be grounded
if(key)
{
clear_lcd();
lcd_str("KEY PASS");
delay(2000);
TX_from_CAN2(2);
up:
a = IOPIN0;
a = (0x00000010 & a); //brake test PORT0 po.4
b = IOPIN0;
b = (0x00000040 & b); //seat belt test PORT0 po.6
if(a == 0 && b == 0)
{
TX_from_CAN2(3);
}
else //if key != 0 (ignition:p0.5 not grounded)
{
goto up;
}
}
else //if key != 0 (ignition:p0.5 not grounded)
{
goto test;
}
}
void can_test(void)
{
unsigned int a,b,key;
test:
lcd_str("TURN ON IGNITION");
delay(2000);
key = IOPIN1;
key = (1<<25) & key; // port po.5 has to be grounded
if(key)
{
clear_lcd();
lcd_str("KEY PASS");
delay(2000);
TX_from_CAN2(2);
up:
a = IOPIN0;
a = (0x00000010 & a); //brake test PORT0 po.4
b = IOPIN0;
b = (0x00000040 & b); //seat belt test PORT0 po.6
if(a == 0 && b == 0)
{
TX_from_CAN2(3);
}
else //if key != 0 (ignition:p0.5 not grounded)
{
goto up;
}
}
else //if key != 0 (ignition:p0.5 not grounded)
{
goto test;
}
}
void CAN_init(void)
{
VPBDIV = 0x02; // 30MHZ
PINSEL1 |= (1<<22)|(1<<24)|(1<<26)|(1<<28)|(1<<18)|(1<<16)|(1<<14);//0x15454000;/*CAN1 intialization*/
{
VPBDIV = 0x02; // 30MHZ
PINSEL1 |= (1<<22)|(1<<24)|(1<<26)|(1<<28)|(1<<18)|(1<<16)|(1<<14);//0x15454000;/*CAN1 intialization*/
/*CAN2 intialization*/
C2MOD=1<<0; /*Reset CAN2 controller*/
C2BTR= 1<<20 | 1<<19 | 1<< 18 | 29; //0x001C001D;/*Set baud Rate for CAN2*/
C2MOD=0; /*Enable CAN2 controller*/
}
/******************************************************/
C2MOD=1<<0; /*Reset CAN2 controller*/
C2BTR= 1<<20 | 1<<19 | 1<< 18 | 29; //0x001C001D;/*Set baud Rate for CAN2*/
C2MOD=0; /*Enable CAN2 controller*/
}
/******************************************************/
void TX_from_CAN2(unsigned int ch)
{
while((C2SR&0X00000004)!=0X00000004);
C2TFI1= (1 << 18);//0X00040000;(DLC)(16:19)send 4 data bytes in the next transmission
C2TDA1=ch; /*Transmit data bytes 1-4 (1)*/
C2TID1=0X045; // tx id
C2CMR= (1 << 0) | (1 << 5); //0X00000021;select transmit buffer 1 and q the message for transmission
while((C2GSR& 0X00000008)!=0X00000008); // Tx has completed Sucessfully
clear_lcd();
lcd_str("Tx successfull");
delay(3000);
}
{
while((C2SR&0X00000004)!=0X00000004);
C2TFI1= (1 << 18);//0X00040000;(DLC)(16:19)send 4 data bytes in the next transmission
C2TDA1=ch; /*Transmit data bytes 1-4 (1)*/
C2TID1=0X045; // tx id
C2CMR= (1 << 0) | (1 << 5); //0X00000021;select transmit buffer 1 and q the message for transmission
while((C2GSR& 0X00000008)!=0X00000008); // Tx has completed Sucessfully
clear_lcd();
lcd_str("Tx successfull");
delay(3000);
}
CODE FOR MAIN
#include "prototype.h"
unsigned char BYTE[9];
unsigned char flag;
unsigned char BYTE[9];
unsigned char flag;
int main()
{
lcd_init();
CAN_init();
clear_lcd();
lcd_str("CAN TEST CODE Tx***");
delay(2000);
can_test();
{
lcd_init();
CAN_init();
clear_lcd();
lcd_str("CAN TEST CODE Tx***");
delay(2000);
can_test();
clear_lcd();
}// end of main
register information
}// end of main
register information
Comments
Post a Comment