avr can芯片使用
时间:11-29
来源:互联网
点击:
#include
struct MOb{unsigned long id;unsigned char data [8];};void can_init (void);void can_tx (struct MOb msg);void can_rx (struct MOb msg);void can_init (void){unsigned char i,j;//reset CAN interfaceCANGCON |= (1baudrate// bit timing -> datasheet 264 (check table)// 250Kbps 16MHz cpu-clkCANBT1 = 0x0E;//16M/8=2MCANBT2 = 0x04;//3QTCANBT3 = 0x13;//2+2=4// clear CAN interrupt registersCANGIE = 0; // none interruptsCANIE1 = 0; // none interrupts on MObsCANIE2 = 0;CANSIT1 = 0;CANSIT2 = 0;//start CAN interfaceCANGCON = (1<1);//wait until module readywhile (!(CANGSTA & (1 >8);CANIDT2 = (unsigned char) (msg.id>>16);CANIDT1 = (unsigned char) (msg.id>>24);//put data in mailboxfor (i=0; i<8; i++)CANMSG = msg.data [i];//enable transmissionCANCDMOB |= (1 > 5);CANIDT2 = (unsigned char)(msg.id >> 13);CANIDT1 = (unsigned char)(msg.id >> 21);// set mask in order to receive only the message with the IDCANIDM4 = 248;CANIDM3 = 255;CANIDM2 = 255;CANIDM1 = 255;// enable extended IDCANIDM4 |= (1 >= 3;}
avrcan芯 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)