led.zip

  • PUDN用户
    了解作者
  • C/C++
    开发工具
  • 2KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 3
    下载次数
  • 2010-12-06 02:49
    上传日期
pic 18f4550 example for turning on an LED Can files are only to make the file big enough for upload
led.zip
  • can.c
    3.2KB
  • can.h
    145B
  • led.c
    420B
内容介绍
#include "p30fxxxx.h" #include "can.h" #include "data.h" //Fcy = Fosc/4 = 5MHz //Fcan = 4Fcy = 20 MHz //TQ (time quanta) = 100ns //Baud rate set at 1MHz, nominal bit time = 10 => nominal bit rate = 1Mbps void can1_init(void) { C1CTRLbits.REQOP = 0b100; //Request Configuration Mode while(C1CTRLbits.OPMODE!=0b100); //Wait for Configuration Mode to be set C1RX0CONbits.DBEN=1; //RX0 Full will write to RX1 C1RXF0SID=8; C1RXF1SID=8; C1RXM0SID=0; C1RXM1SID=0; C1CTRLbits.CANCAP = 0; //Disable CAN capture C1CTRLbits.CSIDL = 0; //Continue CAN module operation in Idle mode C1CTRLbits.CANCKS = 0; //FCAN = 4Fcy = 20MHz //k = 10: 1 +1 +5 +3 C1CFG1bits.SJW=0b00; //Synchronized jump width time is 1xTQ (added to phase 1 or taken from 2 C1CFG1bits.BRP = 0; //TQ = 2/FCAN = 100ns C1CFG2bits.PRSEG=0b000; //length is 1 x TQ C1CFG2bits.SEG2PHTS=1; //Freely programmable C1CFG2bits.SEG1PH=0b100; //lenght is 5 x TQ C1CFG2bits.SEG2PH=0b010; //lenght is 3 x TQ C1INTEbits.RX0IE=1; //RX0 Full interrupt enabled C1INTEbits.RX1IE=1; //RX1 Full interrupt enabled IFS1bits.C1IF=0; //Clear CAN1 Flag IPC6bits.C1IP=0b110; //CAN1 priority is 6 IEC1bits.C1IE=1; //CAN1 interrupts enabled C1TX0CONbits.TXPRI = 3; C1RX0CONbits.RXFUL = 0; C1RX1CONbits.RXFUL = 0; C1CTRLbits.REQOP = 0b000; //Request Normal Mode //RXF0 and RXF1 filters with RXM0 mask are associated //with RXB0. The filters RXF2, RXF3, RXF4, and RXF5 //and the mask RXM1 are associated with RXB1. while(C1CTRLbits.OPMODE!=0b000); //Wait for Normal Mode to be set } void __attribute__((interrupt, auto_psv)) _C1Interrupt(void){ unsigned int sid,lenght,data[4]; if (C1INTFbits.RX0IF) { sid = C1RX0SIDbits.SID; lenght = C1RX0DLCbits.DLC; data[0] = C1RX0B1; data[1] = C1RX0B2; data[2] = C1RX0B3; data[3] = C1RX0B4; C1RX0CONbits.RXFUL = 0; //buffer is no longer full C1INTFbits.RX0IF = 0; //clear buffer msg received flag putData( sid, data ); } if (C1INTFbits.RX1IF) { sid = C1RX1SIDbits.SID; lenght = C1RX1DLCbits.DLC; data[0] = C1RX1B1; data[1] = C1RX1B2; data[2] = C1RX1B3; data[3] = C1RX1B4; C1RX1CONbits.RXFUL = 0; C1INTFbits.RX1IF = 0; putData( sid, data ); } IFS1bits.C1IF=0; } int can1_tx_std(unsigned int sid,unsigned int dlc,unsigned int *data) { unsigned int int_sid; int_sid = ((sid << 5) & 0xF800) | ((sid << 2) & 0x00FC); if (!C1TX0CONbits.TXREQ) { C1TX0SID = int_sid; C1TX0SIDbits.TXIDE = 0; C1TX0SIDbits.SRR = 0; C1TX0DLC = 0; C1TX0DLCbits.DLC = dlc; C1TX0B1 = data[0]; C1TX0B2 = data[1]; C1TX0B3 = data[2]; C1TX0B4 = data[3]; C1TX0CONbits.TXREQ = 1; } else if (!C1TX1CONbits.TXREQ) { C1TX1SID = int_sid; C1TX1SIDbits.TXIDE = 0; C1TX0SIDbits.SRR = 0; C1TX1DLC = 0; C1TX1DLCbits.DLC = dlc; C1TX1B1 = data[0]; C1TX1B2 = data[1]; C1TX1B3 = data[2]; C1TX1B4 = data[3]; C1TX1CONbits.TXREQ = 1; } else if (!C1TX2CONbits.TXREQ) { C1TX2SID = int_sid; C1TX2SIDbits.TXIDE = 0; C1TX0SIDbits.SRR = 0; C1TX2DLC = 0; C1TX2DLCbits.DLC = dlc; C1TX2B1 = data[0]; C1TX2B2 = data[1]; C1TX2B3 = data[2]; C1TX2B4 = data[3]; C1TX2CONbits.TXREQ = 1; } else return 0; return 1; }
评论
    相关推荐
    • big.zip
      这个是一个算法的应用,大数加法,顾名思义,就是大数量级的加法运算
    • big_jiecheng.rar
      java编程,解决大数据的阶乘运算,一般程序只能承载100以内的阶乘运算,超出则运算错误,该程序不限,只要在整数内都可以运算
    • fantagle_big.rar
      Finally i can download my files that's nothing..
    • big.rar
      快速排序,实现输出众多整数中的最大值。并输出比较次数
    • big.gz
      JavaScriptj原代码和示例文档及相关项目资料,妙味课堂原创
    • Big-Int.rar
      hi this is a usefull code for C++ developer, that in C++ , big int code
    • Big Data introduction
      介绍什么是大数据,为何应该关注大数据以及企业应该如何利用大数据来挖掘信息并实现巨大的竞争优势。
    • Understanding Big Data
      Understanding Big Data: Analytics for Enterprise Class Hadoop and Streaming Data Big Data represents a new era in data exploration and utilization, and IBM is uniquely positioned to help clients ...
    • IBM Big Data
      ibm big data 培训资料,对hadoop,biginsight,bigsheet 做了相关介绍
    • BIG DATA.zip
      Big Data from 2018 computer science