微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > AVR单片机实现了232到CAN转换

AVR单片机实现了232到CAN转换

时间:11-27 来源:互联网 点击:

SMPL_1X 0x00

#define PHSEG1_8TQ 0x38

#define PHSEG1_7TQ 0x30

#define PHSEG1_6TQ 0x28

#define PHSEG1_5TQ 0x20

#define PHSEG1_4TQ 0x18

#define PHSEG1_3TQ 0x10

#define PHSEG1_2TQ 0x08

#define PHSEG1_1TQ 0x00

#define PRSEG_8TQ 0x07

#define PRSEG_7TQ 0x06

#define PRSEG_6TQ 0x05

#define PRSEG_5TQ 0x04

#define PRSEG_4TQ 0x03

#define PRSEG_3TQ 0x02

#define PRSEG_2TQ 0x01

#define PRSEG_1TQ 0x00

#define PHSEG2_8TQ 0x07

#define PHSEG2_7TQ 0x06

#define PHSEG2_6TQ 0x05

#define PHSEG2_5TQ 0x04

#define PHSEG2_4TQ 0x03

#define PHSEG2_3TQ 0x02

#define PHSEG2_2TQ 0x01

#define PHSEG2_1TQ 0x00

#define SOF_ENABLED 0x80

#define WAKFIL_ENABLED 0x40

#define WAKFIL_DISABLED 0x00

#define RX0IE_ENABLED 0x01

#define RX0IE_DISABLED 0x00

#define RX1IE_ENABLED 0x02

#define RX1IE_DISABLED 0x00

#define G_RXIE_ENABLED 0x03

#define G_RXIE_DISABLED 0x00

#define TX0IE_ENABLED 0x04

#define TX0IE_DISABLED 0x00

#define TX1IE_ENABLED 0x08

#define TX2IE_DISABLED 0x00

#define TX2IE_ENABLED 0x10

#define TX2IE_DISABLED 0x00

#define G_TXIE_ENABLED 0x1C

#define G_TXIE_DISABLED 0x00

#define ERRIE_ENABLED 0x20

#define ERRIE_DISABLED 0x00

#define WAKIE_ENABLED 0x40

#define WAKIE_DISABLED 0x00

#define IVRE_ENABLED 0x80

#define IVRE_DISABLED 0x00

#define RX0IF_SET 0x01

#define RX0IF_RESET 0x00

#define RX1IF_SET 0x02

#define RX1IF_RESET 0x00

#define TX0IF_SET 0x04

#define TX0IF_RESET 0x00

#define TX1IF_SET 0x08

#define TX2IF_RESET 0x00

#define TX2IF_SET 0x10

#define TX2IF_RESET 0x00

#define ERRIF_SET 0x20

#define ERRIF_RESET 0x00

#define WAKIF_SET 0x40

#define WAKIF_RESET 0x00

#define IVRF_SET 0x80

#define IVRF_RESET 0x00

#define REQOP_CONFIG 0x80

#define REQOP_LISTEN 0x60

#define REQOP_LOOPBACK 0x40

#define REQOP_SLEEP 0x20

#define REQOP_NORMAL 0x00

#define ABORT 0x10

#define OSM_ENABLED 0x08

#define CLKOUT_ENABLED 0x04

#define CLKOUT_DISABLED 0x00

#define CLKOUT_PRE_8 0x03

#define CLKOUT_PRE_4 0x02

#define CLKOUT_PRE_2 0x01

#define CLKOUT_PRE_1 0x00

#define OPMODE_CONFIG 0x80

#define OPMODE_LISTEN 0x60

#define OPMODE_LOOPBACK 0x40

#define OPMODE_SLEEP 0x20

#define OPMODE_NORMAL 0x00

#define RXM_RCV_ALL 0x60

#define RXM_VALID_EXT 0x40

#define RXM_VALID_STD 0x20

#define RXM_VALID_ALL 0x00

#define RXRTR_REMOTE 0x08

#define RXRTR_NO_REMOTE 0x00

#define BUKT_ROLLOVER 0x04

#define BUKT_NO_ROLLOVER 0x00

#define FILHIT0_FLTR_1 0x01

#define FILHIT0_FLTR_0 0x00

#define FILHIT1_FLTR_5 0x05

#define FILHIT1_FLTR_4 0x04

#define FILHIT1_FLTR_3 0x03

#define FILHIT1_FLTR_2 0x02

#define FILHIT1_FLTR_1 0x01

#define FILHIT1_FLTR_0 0x00

#define TXREQ_SET 0x08

#define TXREQ_CLEAR 0x00

#define TXP_HIGHEST 0x03

#define TXP_INTER_HIGH 0x02

#define TXP_INTER_LOW 0x01

#define TXP_LOWEST 0x00

#define DLC_0 0x00

#define DLC_1 0x01

#define DLC_2 0x02

#define DLC_3 0x03

#define DLC_4 0x04

#define DLC_5 0x05

#define DLC_6 0x06

#define DLC_7 0x07

#define DLC_8 0x08

#define CAN_RESET 0xC0

#define CAN_READ 0x03

#define CAN_WRITE 0x02

#define CAN_RTS 0x80

#define CAN_RTS_TXB0 0x81

#define CAN_RTS_TXB1 0x82

#define CAN_RTS_TXB2 0x84

#define CAN_RD_STATUS 0xA0

#define CAN_BIT_MODIFY 0x05

#define CAN_RX_STATUS 0xB0

#define CAN_RD_RX_BUFF 0x90

#define CAN_LOAD_TX 0X40

#define DUMMY_BYTE 0x00

#define TXB0 0x31

#define TXB1 0x41

#define TXB2 0x51

#define RXB0 0x61

#define RXB1 0x71

#define EXIDE_SET 0x08

#define EXIDE_RESET 0x00

uchar can_boud=0x07;//MCP2515在16M晶振情况,can_boud=0x00总线波特率为1M,0x01=500K,0x03=250K,0x07=125K;公式:16M/(16*(1+X))

uint bps=38400;//定义avr单片机串口波特率

uchar eflag=0;//是不是扩展帧,为1则表示接收到的是扩展帧,0表示标准帧

uchar Tdate[10]={0};//存放要发送标准帧的数据,最大10位,前2位是ID号,后8位是数据位

uchar TID[2]={0,0};//存放要发送标准帧的ID号

uchar Rdate[8]={0};//存放接收到的数据

uchar RESID[4];//存放接收到

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top