Download Development of a ZigBee Wireless Sensor Node
Transcript
/* Defines whether the digital pins are going to be inputs or outputs as well as
the values of the latch of each digital buffer*/
void pins_setup(){
/* Should the accelerometer, microphone or TMP sensor be added then some of these registers might need
to be modified. */
TRISB=0x40C1;
LATB=0x00C1;
TRISC=0x9000;
LATC=0x9000;
TRISD=0x060C;
LATD=0x0626;
TRISE=0x0000;
LATE=0x0000;
/* RB0 AN0 (INA_Vout)
RB1 UART2 or Other
RB2 AN2 (Acc_Z)
RB3 AN3 (Acc_Y)
RB4 AN4 (Acc_X)
RB5 AN5 (TMP_Vout)
RB6 ICSP pins
RB7 ICSP pins
RB8 Enable Microphone
RB9 Word Select Microphone
RB10 TMS or other
RB11 TDO or other
RB12 TCK or other
RB13 TDI or other
RB14 I2S DATA Microphone
RB15 I2S CLK Microphone
/* RC12
RC13
RC14
RC15
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
OSCI
unused
unused
OSCO
/* RD0 unused
RD1 UART1 TX
RD2 UART1 RX
RD3 UART1 CTS
RD4 UART1 RTS
RD5 ETRX351 NRESET
RD6 unused
RD7 unused
RD8 unused
RD9 I2C SDA
RD10 I2C SCL
RD11 unused
/* RE 0-7 unused
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
INPUT(1), RB14 mantain as input in any case
OUTPUT(0), No UART2
OUTPUT(0), No Acc
OUTPUT(0), No Acc
OUTPUT(0), No Acc
OUTPUT(0), No TMP
INPUT(1),
INPUT(1),
OUTPUT(0), No Mic
OUTPUT(0), No Mic
OUTPUT(0), No JTAG
OUTPUT(0), No JTAG
OUTPUT(0), No JTAG
OUTPUT(0), No JTAG
INPUT(0), No Mic, but Pull down R connected
OUTPUT(0), No Mic */
INPUT(1),
OUTPUT(0),
OUTPUT(0),
INPUT(1) */
OUTPUT(0),
OUTPUT(1),
INPUT(1),
INPUT(0),
OUTPUT(0),
OUTPUT(1),
OUTPUT(0),
OUTPUT(0),
OUTPUT(0),
INPUT(1),
INPUT(1),
OUTPUT(0)*/
= OUTPUT(0) */
TRISF=0x0028;
LATF=0x0008;
/* RF0 unused
= OUTPUT(0),
RF1 unused
= OUTPUT(0),
RF3 USB ID
= INPUT(1),
RF4 MCP /Shutdown
= OUTPUT(0 HERE)—
(the MCP powers the USB BUS when the PIC 24 is the master),
RF5 MCP PGOOD
= INPUT(0) */
TRISG=0x000C;
LATG=0x000C;
/* RG2
RG3
RG6
RG7
RG8
RG9
USB D+
USB DUART2 or Other
UART2 or Other
UART2 or Other
TMP /Shutdown
=
=
=
=
=
=
INPUT(1),
INPUT(1),
OUTPUT(0),
OUTPUT(0),
OUTPUT(0),
OUTPUT(0),
No
No
No
No
UART2
UART2
UART2
TMP */
}
/* Seeks for an escape sequence in the received data from the ZigBee radio.
When the first character of a possible sequence arrives, it starts a counter.
When a character that continues the sequence arrives, the counter is increased.
When the last character of the sequency arrives, the counter reaches its final value and further measures
will be taken in other functions.
When a character that is not part of the sequency arrives the counter is set to 0.
Escape sequences: OK<CR><LF>
ERROR:XX<CR><LF>
ACK:XX<CR><LF>
**X can be any character */
void check_writebuff(){
switch (writebuff[cnt]){
case 'O':
if( esc == 13 )
esc++;
else
esc=1;
break;
case 'K':
if ( esc == 1 ||esc == 51 )
esc++;
60