发表于:2007-04-17 10:37:00
楼主
下面是精华区中的一个CAN程序,感觉上很好.可刚学,看的很费解,有些语句我加了
加了疑问,看是否有高人能比较完整的分析出每一段的注释,万分感谢了.
这是一个自发收程序,采用at89s51+sja1000,分离晶体,at89s51晶体11.0592
sja1000外部晶体为12M,通过串口进行监控
******************************************************
以下为头文件定义
copyright by alloy
******************************************************
#define SJA_REG_BaseADD 0x7800
#define REG_MODE XBYTE[SJA_REG_BaseADD + 0x00]
#define REG_CMD XBYTE[SJA_REG_BaseADD + 0x01]
#define REG_SR XBYTE[SJA_REG_BaseADD + 0x02]
#define REG_IR XBYTE[SJA_REG_BaseADD + 0x03]
#define REG_IR_ABLE XBYTE[SJA_REG_BaseADD + 0x04]
#define REG_BTR0 XBYTE[SJA_REG_BaseADD + 0x06] //05保留
#define REG_BTR1 XBYTE[SJA_REG_BaseADD + 0x07]
#define REG_OCR XBYTE[SJA_REG_BaseADD + 0x08]
#define REG_TEST XBYTE[SJA_REG_BaseADD + 0x09]
#define REG_ALC XBYTE[SJA_REG_BaseADD + 0x0b] //0a保留
#define REG_ECC XBYTE[SJA_REG_BaseADD + 0x0c]
#define REG_EMLR XBYTE[SJA_REG_BaseADD + 0x0d]
#define REG_RXERR XBYTE[SJA_REG_BaseADD + 0x0e]
#define REG_TXERR XBYTE[SJA_REG_BaseADD + 0x0f]
#define REG_ACR0 XBYTE[SJA_REG_BaseADD + 0x10]
#define REG_ACR1 XBYTE[SJA_REG_BaseADD + 0x11]
#define REG_ACR2 XBYTE[SJA_REG_BaseADD + 0x12]
#define REG_ACR3 XBYTE[SJA_REG_BaseADD + 0x13]
#define REG_AMR0 XBYTE[SJA_REG_BaseADD + 0x14]
#define REG_AMR1 XBYTE[SJA_REG_BaseADD + 0x15]
#define REG_AMR2 XBYTE[SJA_REG_BaseADD + 0x16]
#define REG_AMR3 XBYTE[SJA_REG_BaseADD + 0x17]
#define REG_RxBuffer0 XBYTE[SJA_REG_BaseADD + 0x10] //它和ACR0可重叠位置吗
#define REG_RxBuffer1 XBYTE[SJA_REG_BaseADD + 0x11]
#define REG_RxBuffer2 XBYTE[SJA_REG_BaseADD + 0x12]
#define REG_RxBuffer3 XBYTE[SJA_REG_BaseADD + 0x13]
#define REG_RxBuffer4 XBYTE[SJA_REG_BaseADD + 0x14]
#define REG_TxBuffer0 XBYTE[SJA_REG_BaseADD + 0x10]
#define REG_TxBuffer1 XBYTE[SJA_REG_BaseADD + 0x11]
#define REG_TxBuffer2 XBYTE[SJA_REG_BaseADD + 0x12]
#define REG_TxBuffer3 XBYTE[SJA_REG_BaseADD + 0x13]
#define REG_TxBuffer4 XBYTE[SJA_REG_BaseADD + 0x14]
#define REG_DataBuffer1 XBYTE[SJA_REG_BaseADD + 0x15] //与上述问题一样.
#define REG_DataBuffer2 XBYTE[SJA_REG_BaseADD + 0x16]
#define REG_DataBuffer3 XBYTE[SJA_REG_BaseADD + 0x17]
#define REG_DataBuffer4 XBYTE[SJA_REG_BaseADD + 0x18]
#define REG_DataBuffer5 XBYTE[SJA_REG_BaseADD + 0x19]
#define REG_DataBuffer6 XBYTE[SJA_REG_BaseADD + 0x1a]
#define REG_DataBuffer7 XBYTE[SJA_REG_BaseADD + 0x1b]
#define REG_DataBuffer8 XBYTE[SJA_REG_BaseADD + 0x1c]
#define REG_RBSA XBYTE[SJA_REG_BaseADD + 0x1e]
#define REG_CDR XBYTE[SJA_REG_BaseADD + 0x1f]
#define REG_Receive_Counter XBYTE[SJA_REG_BaseADD + 0x1d]
#define OK 1
#define Fail 0