Download Development of a ZigBee Wireless Sensor Node

Transcript
/* This is the main function. First it makes some function calls to configure and initialize
the microcontroller. Then it enters the main loop.
In the main loop certain task are repeated periodically:
1. -Checks if there is something pending to read in the USB buffer
(the user has introduced text through the HID terminal).
-If so:
-That text is processed calling get_command() and command_process()
-The loop starts over.
-If not:
-Continues to step 2.
2. -If the ADC is ON:
-It checks if there is something pending to be read from the
UART (ZigBee module), if so it is processed.
-Then the AD samples are processed.
-The loop starts over.
3. -If the ADC is OFF, it checks if there is something pending
to be read from the UART (ZigBee module), if so it is processed.
- The loop starts over. */
void main(void){
RCON = 0x0000; // Clear Reset Control Register
pins_setup();
UART_Init();
HID_Enable(&readbuff,&writebuff);
while(1){
while(1){
if( (Nchar = HID_Read()) >= 3){ // Reads the USB-HID command line.
get_command(); // Extracts the command from the reading.
command_process();
}
else if( AD1CON1bits.ADON ){
if( radio1_usb0 ){
if( uart_semaphore >= 63 )// Checks if the ETRX module has sent something to the PIC
rx_uart_process();
}
else if( uart_semaphore )
rx_uart_process();
if( ad_semaphore >= 12 )
// Checks if there is any pending sample to process
ad_process();
}
else if( uart_semaphore ) // Checks if the ETRX module has sent something to the PIC
rx_uart_process();
}
}
}
// The maximum defined transfer rate for the HID class is 64K bytes/sec
/*
UART1_Write_Text("ATS12=0520\r"); // 19200bps + flow control mode
UART1_Write_Text("ATS12=0720\r"); // 38400bps + flow control mode
UART1_Write_Text("ATS12=0C20\r"); // 115200bps + flow control mode
UART1_Write_Text("ATS11=0205\r"); // Enable wake up on UART activity(first input character is discarded)
*/
65