PCDVD數位科技討論區
PCDVD數位科技討論區   註冊 常見問題 標記討論區為已讀

回到   PCDVD數位科技討論區 > 其他群組 > 疑難雜症區
帳戶
密碼
 

回應
 
主題工具
COBRA2005
Advance Member
 
COBRA2005的大頭照
 

加入日期: Aug 2001
您的住址: 台北縣
文章: 405
求救!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( &currentPrimitive );

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( &params.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;
     
      
__________________

我!!!拒收好人卡!!不要變成泡不到馬子的可憐虫!!
我的Blog好人幫本鋪
我的相簿!!好人幫!!來練身材!變成拒收好人卡的好人!!!
我被發好人卡!拒收好人卡的好人!!!
舊 2007-04-29, 09:18 PM #1
回應時引用此文章
COBRA2005離線中  
COBRA2005
Advance Member
 
COBRA2005的大頭照
 

加入日期: Aug 2001
您的住址: 台北縣
文章: 405
// ************************************************************************
// Place a case for each user defined endpoint.
// ************************************************************************

default:
// If the command type was something that requested an acknowledge, we could send back
// KVP_INVALID_ENDPOINT here.
break;
}
APLDiscardRx();
}
break;

case APSDE_DATA_confirm:
if (params.APSDE_DATA_confirm.Status)
{
ConsolePutROMString( (ROM char *)"Error " );
PrintChar( params.APSDE_DATA_confirm.Status );
ConsolePutROMString( (ROM char *)" sending message.\r\n" );
}
else
{
ConsolePutROMString( (ROM char *)" Message sent successfully.\r\n" );
}
currentPrimitive = NO_PRIMITIVE;
break;

case NO_PRIMITIVE:
if (!ZigBeeStatus.flags.bits.bNetworkFormed)
{
if (!ZigBeeStatus.flags.bits.bTryingToFormNetwork)
{
ConsolePutROMString( (ROM char *)"Trying to start network...\r\n" );
params.NLME_NETWORK_FORMATION_request.ScanDuration = 8;
params.NLME_NETWORK_FORMATION_request.ScanChannels.Val = ALLOWED_CHANNELS;
params.NLME_NETWORK_FORMATION_request.PANId.Val = 0xFFFF;
params.NLME_NETWORK_FORMATION_request.BeaconOrder = MAC_PIB_macBeaconOrder;
params.NLME_NETWORK_FORMATION_request.SuperframeOrder = MAC_PIB_macSuperframeOrder;
params.NLME_NETWORK_FORMATION_request.BatteryLifeExtension = MAC_PIB_macBattLifeExt;
currentPrimitive = NLME_NETWORK_FORMATION_request;
}
}
else
{
if (ZigBeeReady())
{

// ************************************************************************
// Place all processes that can send messages here. Be sure to call
// ZigBeeBlockTx() when currentPrimitive is set to APSDE_DATA_request.
// ************************************************************************

}
}
break;

default:
PrintChar( currentPrimitive );
ConsolePutROMString( (ROM char *)" Unhandled primitive.\r\n" );
currentPrimitive = NO_PRIMITIVE;
break;
}
 
__________________

我!!!拒收好人卡!!不要變成泡不到馬子的可憐虫!!
我的Blog好人幫本鋪
我的相簿!!好人幫!!來練身材!變成拒收好人卡的好人!!!
我被發好人卡!拒收好人卡的好人!!!
舊 2007-04-29, 09:20 PM #2
回應時引用此文章
COBRA2005離線中  
COBRA2005
Advance Member
 
COBRA2005的大頭照
 

加入日期: Aug 2001
您的住址: 台北縣
文章: 405
// *********************************************************************
// Place any non-ZigBee related processing here. Be sure that the code
// will loop back and execute ZigBeeTasks() in a timely manner.
// *********************************************************************

}
}

/*******************************************************************************
HardwareInit

All port directioning and SPI must be initialized before calling ZigBeeInit().

For demonstration purposes, required signals are configured individually.
*******************************************************************************/
void HardwareInit(void)
{

//-------------------------------------------------------------------------
// This section is required to initialize the PICDEM Z for the CC2420
// and the ZigBee Stack.
//-------------------------------------------------------------------------

SPIInit();

// CC2420 I/O assignments with respect to PIC:
//NOTE: User must make sure that pin is capable of correct digital operation.
// This may require modificaiton of which pins are digital and analog.
//NOTE: The stack requires that the SPI interface be located on LATC3 (SCK),
// RC4 (SO), and LATC5 (SI).
//NOTE: The appropriate config bit must be set such that FIFOP is the CCP2
// input pin. The stack uses the CCP2 interrupt.

// Start with CC2420 disabled and not selected
PHY_CSn = 1;
PHY_VREG_EN = 0;
PHY_RESETn = 1;

// Set the directioning for the CC2420 pin connections.
PHY_FIFO_TRIS = 1; // FIFO (Input)
PHY_SFD_TRIS = 1; // SFD (Input - Generates interrupt on falling edge)
PHY_FIFOP_TRIS = 1; // FIFOP (Input - Used to detect overflow, CCP2 interrupt)
PHY_CSn_TRIS = 0; // CSn (Output - to select CC2420 SPI slave)
PHY_VREG_EN_TRIS = 0; // VREG_EN (Output - to enable CC2420 voltage regulator)
PHY_RESETn_TRIS = 0; // RESETn (Output - to reset CC2420)

// Initialize the SPI pins and directions
LATC3 = 1; // SCK
LATC5 = 1; // SDO
TRISC3 = 0; // SCK
TRISC4 = 1; // SDI
TRISC5 = 0; // SDO

// Initialize the SPI module
SSPSTAT = 0xC0;
SSPCON1 = 0x20;

//-------------------------------------------------------------------------
// This section is required for application-specific hardware
// initialization.
//-------------------------------------------------------------------------

// D1 and D2 are on RA0 and RA1 respectively, and CS of the TC77 is on RA2.
// Make PORTA digital I/O.
ADCON1 = 0x0F;

// Deselect the TC77 temperature sensor (RA2)
LATA = 0x04;

// Make RA0, RA1, RA2 and RA4 outputs.
TRISA = 0xE0;

// Clear the RBIF flag (INTCONbits.RBIF)
RBIF = 0;

// Enable PORTB pull-ups (INTCON2bits.RBPU)
RBPU = 0;

// Make the PORTB switch connections inputs.
TRISB4 = 1;
TRISB5 = 1;
}

/*******************************************************************************
User Interrupt Handler

The stack uses some interrupts for its internal processing. Once it is done
checking for its interrupts, the stack calls this function to allow for any
additional interrupt processing.
*******************************************************************************/

void UserInterruptHandler(void)
{

// *************************************************************************
// Place any application-specific interrupt processing here
// *************************************************************************

}
__________________

我!!!拒收好人卡!!不要變成泡不到馬子的可憐虫!!
我的Blog好人幫本鋪
我的相簿!!好人幫!!來練身材!變成拒收好人卡的好人!!!
我被發好人卡!拒收好人卡的好人!!!
舊 2007-04-29, 09:21 PM #3
回應時引用此文章
COBRA2005離線中  


回應


POPIN
主題工具

發表文章規則
不可以發起新主題
不可以回應主題
不可以上傳附加檔案
不可以編輯您的文章

vB 代碼打開
[IMG]代碼打開
HTML代碼關閉



所有的時間均為GMT +8。 現在的時間是11:21 PM.


vBulletin Version 3.0.1
powered_by_vbulletin 2025。