• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users






Re: 求救!!PIC 18問題...接手別人低!!
#2
版主
版主


查看用戶資訊
我個人認為你接了一個燙手山竽,ZigBee 是個蠻複雜的 Protocol 。你需要先了解 ZigBee 的規範及各個通訊層的意義與協定,上網找一下ZigBee 的規範吧!

Microchip所提供資網站資料如下,你所貼的程式只是其中一小部份而已。
http://www.microchip.com/stellent/idc ... e=SS_GET_PAGE&nodeId=2112

發表於: 2007/4/29 23:40
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


求救!!PIC 18問題...接手別人低!!
#1
新會員
新會員


查看用戶資訊
這是學長的專題,老師點名我這不會寫程式...接手這程式!!要問我程式!明天要問我作了些啥!打成績...!我也到圖書館借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;

// ************************************************************************
// 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;
}

// *********************************************************************
// 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
// *************************************************************************

}

發表於: 2007/4/29 21:18
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------