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

📄 main.c

📁 This library is Copyright (c) Raphael Zulliger <zulli@gmx.net>. It is licensed under the GNU L
💻 C
字号:

//----------------------------------------------------------------------------

#include <p18c658.h>
#include <delays.h>

// CANopen related includes
#include <def.h>
#include <init.h>
#include <can18xx8.h>
#include <pdo.h>
#include <objdict.h>
#include <objacces.h>
#include <lifegrd.h>
#include <timer.h>
#include <nmt.h>

#include <app.h>

// because of the bug-workaround
#include <general.h>
#include <canop.h>

//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
//    Defines
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
//    Funktions Prototypen
//----------------------------------------------------------------------------
void SetupCanbus(void);
void main(void);





//----------------------------------------------------------------------------
//    SetupCanbus(void)
//
//----------------------------------------------------------------------------
void SetupCanbus(void)
{
	BYTE i;
	
	sInitParameter param;

	// initialize canopen device
	param.bNodeID = PORTC & (BYTE)0x7F;	// gets the node-id from the dip-switch
	param.wBaudRateIndex = b125k;
	param.wProcSpeed = (WORD)FOSC;
	initConnection( &param );

	// !!!!!!! should be changed!
	// dirty hack: canMessageRxBuffer should be initialized by values... but 
	// i couln't manage to get it work. so do it here.
	for( i=0; i<RX_CAN_BUFFER_SIZE; i++ )
	{
		canMessageRxBuffer[i].valid = FALSE;
	}
}



//----------------------------------------------------------------------------
// Main routine
//----------------------------------------------------------------------------
void main(void)
{
	// start state machine
	bStateMachineState = INITIALISATION_COMMUNICATION;

	while(1) 
	{
		switch( bStateMachineState )
		{
			case INITIALISATION_COMMUNICATION:
					// init canbus
					SetupCanbus( );
					initTimer( );
					// change automatically into initialisation of the node
					bStateMachineState = INITIALISATION_NODE;
					break;
			case INITIALISATION_NODE:
					// because sending of heartbeat must start just after bootup, lets do that...
					// the first message has to be the boot-up message (with first data-byte
					// set to 0, therefore we have to send this heartbeat NOW.
					initialisation( );
					// create the list with all heartbeat-entries...
					lifeguardInit( );
					sendBootUp( );
					bStateMachineState = PRE_OPERATIONAL;
					break;
			case PRE_OPERATIONAL:
					preOperational( );
					break;
			case OPERATIONAL:
					operational( );
					break;
			case STOPPED:
					stopped( );
					break;
		}
	}
}





⌨️ 快捷键说明

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