My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
XbeeCode  
Updated Dec 1, 2013 by rijadsul...@gmail.com

Code

/******************************************************************************/
/* Files to Include                                                           */
/******************************************************************************/
 
#include <p18cxxx.h>        /* C18 General Include File */
#include "system.h"         /* System funct/params, like osc/peripheral config */
#include "user.h"           /* User funct/params, such as InitApp */
 
#include <usart.h>
#include <delays.h>
 
#pragma config OSC = HS
#pragma config WDT = OFF       //Disables Watchdog Timer
 
 
int i;
const unsigned char delimiter = 0x7E;
unsigned char length;
unsigned char frameType = 0x10;
unsigned char frameID = 0x01;
unsigned char radius = 0x00;
unsigned char options = 0x00;
char checkSum = 0x00;
 
 
void main(void)
{
 
    OSCCON = 0b01110111;
 
    TRISBbits.TRISB1 = 0;   //TX
    TRISBbits.TRISB4 = 1;   //RX
 
 
    OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF
            & USART_ASYNCH_MODE & USART_EIGHT_BIT
            & USART_SINGLE_RX & USART_BRGH_LOW, 12);  // try 12, 51, 207
 
    Delay1KTCYx(4);
 
 
    while(1)
    {
 
        // Start Delimiter
        while(BusyUSART());
        WriteUSART(delimiter);
 
 
        // Length
        // 14 + 9 = 23 in hex
        while(BusyUSART());
        WriteUSART(0x00);
        while(BusyUSART());
        // Payload length + FrameTypeLen + FrameIDLen + 64DestAddressLen + 16DestLen + RadiusLen + optionsLen
        WriteUSART(9 + 14);
 
 
        // Frame Type
        while(BusyUSART());
        WriteUSART(frameType);
 
 
        // Frame ID - API Mode 1
        while(BusyUSART());
        WriteUSART(frameID);
        checkSum += frameID;
 
        // 64-bit Destination Address
        // All Zeros
        for (i = 0; i < 8; i++)
        {
            while(BusyUSART());
            WriteUSART(0x00);
            checkSum += frameID;
        }
 
        // 16-bit Address
        // 0xFFFE
        while(BusyUSART());
        WriteUSART(0xFF);
        checkSum += 0xFF;
 
        while(BusyUSART());
        WriteUSART(0xFE);
        checkSum += 0xFE;
 
 
        // Broadcast Radius
        while(BusyUSART());
        WriteUSART(radius);
        checkSum += radius;
 
 
        // Options
        // Checksum = 17 here
        while(BusyUSART());
        WriteUSART(options);
        checkSum += options;
 
 
        // Payload
        // Fount1Win = 9 Bytes
        while(BusyUSART());
        WriteUSART('F');
        while(BusyUSART());
        WriteUSART('1');
        while(BusyUSART());
        WriteUSART('W');
        while(BusyUSART());
        WriteUSART('I');
        while(BusyUSART());
        WriteUSART('N');
        checkSum += 5;
 
 
        // Checksum: total bytes = 26
        // in Hex
        checkSum = (char)(0xFF - (char)checkSum);
        while(BusyUSART());
        WriteUSART((char)checkSum);
 
 
        Delay10KTCYx(100);
        Delay10KTCYx(100);
        Delay10KTCYx(100);
        Delay10KTCYx(100);
        Delay10KTCYx(100);
 
    }
}
Powered by Google Project Hosting