/************************************************************************
Reference address:One use of pointers (optimizing code)
函数名 :unsigned char CAN_Send_dat(CAN_DAT *can_tmp,unsigned char pir) Function: can send Parameter: *can_tmp data packet pir: priority 0~3 Return: 1->The buffer pool is full and needs to wait for the next load to send the buffer pool 0->Successfully put into the buffer pool ************************************************************************/ unsigned char CAN_Send_dat(CAN_DAT *can_tmp,unsigned char pir) { unsigned char n,flag; unsigned char temp; unsigned char *P_addr,*P_addr_temp; flag = 0; if((TXB0CON&0x08)==0) { P_addr = (unsigned char*)(&TXB0CON); flag = 1; } if((TXB1CON&0x08)==0) { P_addr = (unsigned char*)(&TXB1CON); flag = 1; } if((TXB2CON&0x08)==0) { P_addr = (unsigned char*)(&TXB2CON); flag = 1; } if(flag==1) { P_addr_temp = P_addr; *P_addr = pir; P_addr++; if(can_tmp->IDR_RTR&0x02)//Extended identifier { *P_addr = ((can_tmp->ID[2]>>5)|(can_tmp->ID[3]<<3)); temp = can_tmp->ID[2]&0x03; temp|=((can_tmp->ID[2]&0x1C)<<3); temp|= 0x08; P_addr++; *P_addr = temp; P_addr++; *P_addr = can_tmp->ID[1]; P_addr++; *P_addr = can_tmp->ID[0]; P_addr++; } else { *P_addr = ((can_tmp->ID[1]<<5)|(can_tmp->ID[0]>>3));; P_addr++; *P_addr = (can_tmp->ID[0]<<5); P_addr+=3; } *P_addr = can_tmp->length; P_addr++; for(n=0;nlength;n++) { *P_addr =can_tmp->DATA[n]; P_addr++; } *P_addr_temp |= 0x08; return 0; } return 1; } /************************************************************************ 函数名 :unsigned char CAN_Send_dat(CAN_DAT *can_tmp,unsigned char pir) Function: can send Parameter: *can_tmp data packet pir: priority 0~3 Return: 1->The buffer pool is full and needs to wait for the next load to send the buffer pool 0->Successfully put into the buffer pool ************************************************************************/ unsigned char CAN_Send_dat(CAN_DAT *can_tmp,unsigned char pir) { unsigned char n; unsigned char temp; unsigned char *P_addr; if((TXB0CON&0x08)==0) { // TXB0CON&=0xfc; //bit3=0 standard identifier, bit3=1 extended identifier, bit7-5: standard identifier 2-0, bit7-5 extended ID[16-17] TXB0CON = pir; //|= pir; //Set TXB0 to the highest priority 3 if(can_tmp->IDR_RTR&0x02)//Extended identifier { TXB0EIDL = can_tmp->ID[0]; //Extended ID[0-7] TXB0EIDH = can_tmp->ID[1]; //Extended ID[8-15] TXB0SIDL = can_tmp->ID[2]&0x03; //Extended ID[16-17] temp= ((can_tmp->ID[2]&0x1C)<<3); TXB0SIDL |= temp; //Standard [0-3] TXB0SIDL |= 0x08; TXB0SIDH=((can_tmp->ID[2]>>5)|(can_tmp->ID[3]<<3));//10-3 bits of the standard identifier } else { TXB0SIDL = (can_tmp->ID[0]<<5); //Standard [0-3] TXB0SIDH = ((can_tmp->ID[1]<<5)|(can_tmp->ID[0]>>3)); } //if(can_tmp->IDR_RTR&0x01)can_tmp->length|=0x40; TXB0DLC=can_tmp->length; P_addr = &TXB0D0; for(n=0;n length;n++) { *P_addr =can_tmp->DATA[n]; P_addr++; } TXB0CON=TXB0CON|0x08; /* bit3(TXREQ)=1 request to send*/ return 0; } if((TXB1CON&0x08)==0) { // TXB1CON&=0xfc; TXB1CON = pir;//|= pir; if(can_tmp->IDR_RTR&0x02)//Extended identifier { TXB1EIDL = can_tmp->ID[0]; //Extended ID[0-7] TXB1EIDH = can_tmp->ID[1]; //Extended ID[8-15] TXB1SIDL = can_tmp->ID[2]&0x03; //Extended ID[16-17] temp= ((can_tmp->ID[2]&0x1C)<<3); TXB1SIDL |= temp; //Standard [0-3] TXB1SIDL |= 0x08; TXB1SIDH=((can_tmp->ID[2]>>5)|(can_tmp->ID[3]<<3));//10-3 bits of the standard identifier } else { TXB1SIDL = (can_tmp->ID[0]<<5); //Standard [0-3] TXB1SIDH = ((can_tmp->ID[1]<<5)|(can_tmp->ID[0]>>3)); } //if(can_tmp->IDR_RTR&0x01)can_tmp->length|=0x40; TXB1DLC=can_tmp->length; P_addr = &TXB1D0; for(n=0;n length;n++) { *P_addr =can_tmp->DATA[n]; P_addr++; } TXB1CON=TXB1CON|0x08; return 0; } if((TXB2CON&0x08)==0) { //TXB2CON&=0xfc; TXB2CON = pir; if(can_tmp->IDR_RTR&0x02)//Extended identifier { TXB2EIDL = can_tmp->ID[0]; //Extended ID[0-7] TXB2EIDH = can_tmp->ID[1]; //Extended ID[8-15] TXB2SIDL = can_tmp->ID[2]&0x03; //Extended ID[16-17] temp= ((can_tmp->ID[2]&0x1C)<<3); TXB2SIDL |= temp; //Standard [0-3] TXB2SIDL |= 0x08; TXB2SIDH=((can_tmp->ID[2]>>5)|(can_tmp->ID[3]<<3));//10-3 bits of the standard identifier } else { TXB2SIDL = (can_tmp->ID[0]<<5); //Standard [0-3] TXB2SIDH = (can_tmp->ID[1]<<5|(can_tmp->ID[0]>>3)); } // if(can_tmp->IDR_RTR&0x01)can_tmp->length|=0x40; TXB2DLC=can_tmp->length; P_addr = &TXB2D0; for(n=0;n length;n++) { *P_addr =can_tmp->DATA[n]; P_addr++; } TXB2CON=TXB2CON|0x08; return 0; } return 1; }
Previous article:To the Junior Students of the Department of Electronics—Introduction
Next article:sd card read and write spi mode
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
MoreDaily News
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
Guess you like
- Unattended Brushless DC Motor System
- Analysis of the voltage following circuit of the operational amplifier
- Detailed explanation of ADC of MSP430 microcontroller
- [GD32L233C-START Review] Part 1: Unboxing, Hardware Review
- How does the Allwinner V853 chip support the ssh function?
- Tina ti cannot simulate LC oscillation circuit!
- USB network port module test based on TI Sitara Cortex-A8
- How to output multiple pulses?
- Network port control output TTL module
- Power charging circuit