⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 开放源码的CanOpen源码(C)
💻 C
字号:
/*******************************************************************************

    main.c - Main and ISR functions
    
    Copyright (C) 2004  Janez Paternoster, Slovenia

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


    Author: janez.paternoster@siol.net

    History:
    2004/06/25 [JP]  File Created
    2004/08/09 [JP]  Revised, some changes

*******************************************************************************/

#include <p18cxxx.h>  

#include "CANopDriver.h"
#include "CANopErrors.h"


/* CANopen function prototypes ************************************************/
   void CO_InitResetNode(void);
   void CO_InitResetComm(void);
   void CO_IsrCANtxErr(void);  //ISR for transmitting CAN messages and error handling
   void CO_IsrProcess1ms(void);//Process CANopen from 1ms interrupt, synchronous
   void CO_IsrHigh(void);      //ISR for reciving CAN messages
   void CO_ProcessMain(void);  //Process CANopen from main function, asynchronous

/* INTERRUPTS *****************************************************************/
   #pragma interruptlow IsrLow save = CANCON, PROD, TBLPTR, TABLAT, section(".tmpdata"), section("MATH_DATA")
   void IsrLow (void){
      PCB_BANDWIDTH_IsrLow(1);
      if(PIR1bits.TMR2IF){
         PIR1bits.TMR2IF = 0;
         CO_IsrProcess1ms();
         User_1msISR();
         if(PIR1bits.TMR2IF) ErrorReport(ERROR_isr_timer_overflow, 0);
         }
      else if(PIR3 & PIE3 & 0xFC){
         CO_IsrCANtxErr();
      }
      else 
         ErrorReport(ERROR_isr_low_WrongInterrupt, 0);
      PCB_BANDWIDTH_IsrLow(0);
   }
      
   #pragma code high_vector=0x08
      void interrupt_high(void){
         _asm 
            MOVF PIR3, 0, ACCESS
            ANDLW 0x3
            BZ M_LAB_1
            GOTO CO_IsrHigh 
           M_LAB_1:
            GOTO User_IsrHigh
         _endasm
      }
   #pragma code
      
   #pragma code low_vector=0x18
      void interrupt_low(void){_asm GOTO IsrLow _endasm}
   #pragma code 
   
   
/* main() *********************************************************************/
void main (void){
   User_InitResetNode();
   CO_InitResetNode();
   CO_InitResetComm();

   //interrupts
   RCONbits.IPEN   = 1;    //interrupt priority enable
   INTCONbits.GIEL = 1;    //global peripheral interrupt low enable
   INTCONbits.GIEH = 1;    //global interrupt high enable

   while(1){
      ClrWdt();
      CO_ProcessMain();
      ClrWdt();
      User_Main();
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -