|
Advance Member
|
求救!C語言!!Zigbee PIC18LF2520問題...接手別人低!!
求救!!PIC 18問題...接手別人低!!
這是學長的專題,老師點名我這不會寫程式...接手這程式!!要問我程式!明天要問我作了些啥!打成績...!我也到圖書館借C的書來看!也是都看不懂....
請問這是個....zigbee 用PIC18LF2520當微處理器接zigbee,應該說整快是實驗版!!
這是學長改的程式...請問我該怎跟老師說這是幹啥的...我要先跟老師解釋我了解多少...
// Include the main ZigBee header file.
#include "zAPL.h"
// If you are going to send data to a terminal, include this file.
#include "console.h"
//******************************************************************************
// Configuration Bits
//******************************************************************************
#if defined(MCHP_C18) && defined(__18F4620)
#pragma romdata CONFIG1H = 0x300001
const rom unsigned char config1H = 0b00000110; // HSPLL oscillator
#pragma romdata CONFIG2L = 0x300002
const rom unsigned char config2L = 0b00011111; // Brown-out Reset Enabled in hardware @ 2.0V, PWRTEN disabled
#pragma romdata CONFIG2H = 0x300003
const rom unsigned char config2H = 0b00010010; // HW WD disabled, 1:512 prescaler
#pragma romdata CONFIG3H = 0x300005
const rom unsigned char config3H = 0b10000000; // PORTB digital on RESET
#pragma romdata CONFIG4L = 0x300006
const rom unsigned char config4L = 0b10000001; // DEBUG disabled,
// XINST disabled
// LVP disabled
// STVREN enabled
#pragma romdata
#elif defined(HITECH_C18) && defined(_18F4620)
// Set configuration fuses for HITECH compiler.
__CONFIG(1, 0x0600); // HSPLL oscillator
__CONFIG(2, 0x101F); // PWRTEN disabled, BOR enabled @ 2.0V, HW WD disabled, 1:128 prescaler
__CONFIG(3, 0x8000); // PORTB digital on RESET
__CONFIG(4, 0x0081); // DEBUG disabled,
// XINST disabled
// LVP disabled
// STVREN enabled
#endif
//******************************************************************************
// Function Prototypes
//******************************************************************************
void HardwareInit( void );
//******************************************************************************
// Application Variables
//******************************************************************************
ZIGBEE_PRIMITIVE currentPrimitive;
//******************************************************************************
//******************************************************************************
//******************************************************************************
void main(void)
{
CLRWDT();
ENABLE_WDT();
currentPrimitive = NO_PRIMITIVE;
// If you are going to send data to a terminal, initialize the UART.
ConsoleInit();
// Initialize the hardware - must be done before initializing ZigBee.
HardwareInit();
// Initialize the ZigBee Stack.
ZigBeeInit();
// *************************************************************************
// Perform any other initialization here
// *************************************************************************
// Enable interrupts to get everything going.
IPEN = 1;
GIEH = 1;
while (1)
{
CLRWDT();
ZigBeeTasks( ¤tPrimitive );
switch (currentPrimitive)
{
case NLME_NETWORK_FORMATION_confirm:
if (!params.NLME_NETWORK_FORMATION_confirm.Status)
{
ConsolePutROMString( (ROM char *)"PAN " );
PrintChar( macPIB.macPANId.byte.MSB );
PrintChar( macPIB.macPANId.byte.LSB );
ConsolePutROMString( (ROM char *)" started successfully.\r\n" );
params.NLME_PERMIT_JOINING_request.PermitDuration = 0xFF; // No Timeout
currentPrimitive = NLME_PERMIT_JOINING_request;
}
else
{
PrintChar( params.NLME_NETWORK_FORMATION_confirm.Status );
ConsolePutROMString( (ROM char *)" Error forming network. Trying again...\r\n" );
currentPrimitive = NO_PRIMITIVE;
}
break;
case NLME_PERMIT_JOINING_confirm:
if (!params.NLME_PERMIT_JOINING_confirm.Status)
{
ConsolePutROMString( (ROM char *)"Joining permitted.\r\n" );
currentPrimitive = NO_PRIMITIVE;
}
else
{
PrintChar( params.NLME_PERMIT_JOINING_confirm.Status );
ConsolePutROMString( (ROM char *)" Join permission unsuccessful. We cannot allow joins.\r\n" );
currentPrimitive = NO_PRIMITIVE;
}
break;
case NLME_JOIN_indication:
ConsolePutROMString( (ROM char *)"Node " );
PrintChar( params.NLME_JOIN_indication.ShortAddress.byte.MSB );
PrintChar( params.NLME_JOIN_indication.ShortAddress.byte.LSB );
ConsolePutROMString( (ROM char *)" just joined.\r\n" );
currentPrimitive = NO_PRIMITIVE;
break;
case NLME_LEAVE_indication:
if (!memcmppgm2ram( ¶ms.NLME_LEAVE_indication.DeviceAddress, (ROM void *)&macLongAddr, 8 ))
{
ConsolePutROMString( (ROM char *)"We have left the network.\r\n" );
}
else
{
ConsolePutROMString( (ROM char *)"Another node has left the network.\r\n" );
}
currentPrimitive = NO_PRIMITIVE;
break;
case NLME_RESET_confirm:
ConsolePutROMString( (ROM char *)"ZigBee Stack has been reset.\r\n" );
currentPrimitive = NO_PRIMITIVE;
break;
case APSDE_DATA_indication:
{
WORD_VAL attributeId;
BYTE command;
BYTE data;
BYTE dataLength;
//BYTE dataType;
BYTE frameHeader;
BYTE sequenceNumber;
BYTE transaction;
BYTE transByte;
currentPrimitive = NO_PRIMITIVE;
frameHeader = APLGet();
switch (params.APSDE_DATA_indication.DstEndpoint)
{
case EP_ZDO:
if ((frameHeader & APL_FRAME_TYPE_MASK) == APL_FRAME_TYPE_MSG)
{
frameHeader &= APL_FRAME_COUNT_MASK;
for (transaction=0; transaction<frameHeader; transaction++)
{
sequenceNumber = APLGet();
dataLength = APLGet();
transByte = 0;
switch( params.APSDE_DATA_indication.ClusterId )
{
// ********************************************************
// Put a case here to handle each ZDO response that we requested.
// Be sure to increment transByte for each APLGet().
// ********************************************************
default:
break;
}
// Read out the rest of the MSG in case there is another transaction.
for (; transByte<dataLength; transByte++)
{
APLGet();
}
}
}
break;
|