Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Wireless Sensor Network (WSN),that composed from coordinator and 3 end nodes with Zigbee technology ,connected the coordinator to the PC by serial port and opened it with C#. the coordinator collect the data (temperature reading from temperature sensor) from the 3 end nodes and monitor it on c# design and also save it in DB , Now i want to compare the data i get from the sensor with a set point i set it in the coordinator , if the data read greater than the set point the fan on PORTA.f0=1 else PORTA.f0=0.

C
float temp_res=0;
float temp;
const unsigned short VREF = 4.75;
char address;
char txt[4];
char FanStatus=0x66;     // fals(f)=0x66

void main() {
ANSEL = 0x02;               //Configure AN1 pin as analog
TRISA = 0x02;               //Configure AN1 pin as input
ANSEL = 0X00;              //configure AN0 pin as digital
TRISA = 0X00;               //configure AN0 pin as an output pin
TRISB  = 0;                 //configure POrt B as an output port
PORTB=0;

        ADC_Init();                               //Initialize the ADC
        UART1_Init(9600);                         //Initialize the UART with 9600Kbps Baud Rate
        Delay_ms(100);                           // Wait for UART module to stabilize
       PORTA.f0 = 0;                            // FAN initially OFF
 while(1){    temp_res = ADC_Get_Sample(1);      //Get temp readings from ADC module
              temp = (temp_res * VREF)/10.240;
              floatToStr(temp, txt);

           if (UART1_Tx_Idle()==1)                 // end if idel
              {
                 UART1_Write_Text("z");
                 UART1_Write(FanStatus);
                 UART1_Write_Text(txt);
                 UART1_Write_Text("end");
               }
               
            if (UART1_Data_Ready()==1)              //If data is received
               { address=UART1_Read();              // read the address
                  if(address==(0x7A))               //if the address=z
                     {
                PORTA.f0 = !PORTA.f0 ;        // switch FAN ON/OFF
                if(PORTA.f0==1)
                      {
                         FanStatus=0x74;  //true
                      }
                else if (PORTA.f0==0)
                      {
                          FanStatus=0x66;   //fals
                      }
                     }
               }                                   // end if ready
                     delay_ms(10000);
          }                                       // end while

            }                                     //end main


[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 13-Dec-14 20:59pm
v5
Comments
PIEBALDconsult 13-Dec-14 14:25pm    
How are we to know? You tell us.
MuntahaJameel 13-Dec-14 14:30pm    
I don't know so i asked you!!!!
PIEBALDconsult 13-Dec-14 14:32pm    
We don't know anything about what it's supposed to do.
Additionally, the question "I HAVE WROTE THIS PROGRAM ,IS THAT RIGHT?" is actually asking whether or not you wrote it -- and we don't even know that.
MuntahaJameel 13-Dec-14 14:47pm    
Sorry did not give details of the work, i have a Wireless Sensor Network (WSN),that composed from coordinator and 3 end nodes with Zigbee technology ,connected the coordinator to the PC by serial port and opened it with C#. the coordinator collect the data (temperature reading from temperature sensor) from the 3 end nodes and monitor it on c# design and also save it in DB , Now i want to compare the data i get from the sensor with a set point i set it in the coordinator , if the data read greater than the set point the fan on PORTA.f0=1 else PORTA.f0=0.
PIEBALDconsult 13-Dec-14 14:49pm    
Please use Improve question to add that detail to the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900