Send routine for the sensors


void send_package(void){ 
 
  int i;
   
  int d; 

  P1DIR |= 0x0C;                            // Set P1.2 & 3 to output direction
 
  P1OUT &= 0x03;                            // set P1.3 low to mark start of no snooze 
 
  for( d = 0; d < 500 ; d++);
 
  P1OUT |= 0x08;                            // set P1.3 high to mark start transmission 
    
   send_char('A');                          // identify the solar panel by an A
   
   make_string(sample_scaled);              // format and send current amps

   for(i = 0x01; i < 3 ; i++)
    send_char(st[i]);
   
   make_string(sample_max);                 // format and send max

   for(i = 0x01; i < 3 ; i++)
    send_char(st[i]);

   make_string(amp_hour);                   // format and send last hours amps

   for(i = 0x0; i < 3 ; i++)
    send_char(st[i]);
         
   make_string(amp_per_day);               // format and send last 24 hours amps
  
   for(i = 0x0; i < 3 ; i++)
     send_char(st[i]);

   P1OUT |= 0x04;                            // set P1.2 high  
    
   seconds = seconds + 1;
          
   if(seconds >=60){
            
     seconds = 0;
            
     minutes++;
            
     if (minutes >= 60){
              
       minutes = 0;              

       hours++;
       
       calculate_amp_hour(); 
     
       if(hours>=24)
         hours = 0;            
    }   
  } 

void send_char(char p_i){

  int p,i,j; 
 
  P1OUT |= 0x02;
 
  BCSCTL1 |= RSEL3 | RSEL2 | RSEL1 | RSEL0; // increase speed
 
  P1DIR |= 0x02;                            // Set P1.1 to output direction

    p = (int) p_i;
 
    p = p << 1;
   
    p |= 0x200;                           // add start and stop bit
 
  for(i = 0; i < 10 ;i++){
  
    for(j = 0; j < SERIAL_DELAY_9600; j++);
   
    if((p & 0x01) != 0)
           
      P1OUT = 0x02;  // set bit high
   
    else
     
      P1OUT = 0x00;   // set bit low
       
    p = p >> 1;   
   
  } 
 
  P1OUT |= 0x02;
    for(j = 0; j < SERIAL_DELAY; j++);

    BCSCTL1 = RSEL2 | RSEL1 | RSEL0; // reduce speed


void calculate_amp_hour(void){
 
int i;
   
    amp_hour = sum / amp_divider;
    sum = 0;
    sample_max = sample_scaled;
 
    for(i = 23 ; i >= 0 ; i--){
   
      amp_history[i] = amp_history[i-1];  // rotate last 23 hours
     
    }    
   
     amp_history[0] = amp_hour;           // insert latest hour
   
    amp_per_day = 0;
   
    for(i = 23 ; i >= 0 ; i--){
   
      amp_per_day += amp_history[i]; 
     
    }     


Kommentarer

Kommentera inlägget här:

Namn:
Kom ihåg mig?

E-postadress: (publiceras ej)

URL/Bloggadress:

Kommentar:

Trackback
RSS 2.0