Esempio n. 1
0
//----------------------------------------------------------
//Check to see if the LCD is working - output LCD Error if it isn't
//Should change this so that it doesn't go on forever.
void check(short status){	 // 0 if LCD is broken
  if(status ==0){		   
    for(;;) {
      SCI_OutString("LCDError");   OutCRLF();
      Timer_mwait(250);    // 0.25 sec wait
    }
  }
}
//-----------------------SCI_OutFix1-----------------------
// Output a 16-bit number in unsigned decimal fixed-point
// with resolution = 0.1 
// Input: SCI port, 16-bit unsigned number 
// Output: none
// fixed size 5 digits of output, right justified
// if input is 12345, then display is 1234.5 
void SCI_OutFix1(unsigned char port, unsigned short n){
  if(n < 10){
    SCI_OutString(port, "   0.");
    SCI_OutChar(port, n+'0'); /* n is between 0 and 9 */
  } else if(n<100){
    SCI_OutString(port, "   ");
    SCI_OutChar(port, n/10+'0'); /* tens digit */
    SCI_OutChar(port, '.');      /* decimal point */
    SCI_OutChar(port, n%10+'0'); /* ones digit */
  } else if(n<1000){
      SCI_OutString(port, "  ");
      SCI_OutChar(port, n/100+'0'); /* hundreds digit */
      n = n%100;
      SCI_OutChar(port, n/10+'0'); /* tens digit */
      SCI_OutChar(port, '.');      /* decimal point */
      SCI_OutChar(port, n%10+'0'); /* ones digit */
    }
    else if(n<10000){
      SCI_OutChar(port, ' ');  
      SCI_OutChar(port, n/1000+'0'); /* thousands digit */
      n = n%1000;
      SCI_OutChar(port, n/100+'0'); /* hundreds digit */
      n = n%100;
      SCI_OutChar(port, n/10+'0'); /* tens digit */
      SCI_OutChar(port, '.');      /* decimal point */
      SCI_OutChar(port, n%10+'0'); /* ones digit */
    }
    else {
      SCI_OutChar(port, n/10000+'0'); /* ten-thousands digit */
      n = n%10000;
      SCI_OutChar(port, n/1000+'0'); /* thousands digit */
      n = n%1000;
      SCI_OutChar(port, n/100+'0'); /* hundreds digit */
      n = n%100;
      SCI_OutChar(port, n/10+'0'); /* tens digit */
      SCI_OutChar(port, '.');      /* decimal point */
      SCI_OutChar(port, n%10+'0'); /* ones digit */
    }
}
//-----------------------SCI_SOutFix2-----------------------
// Output a 16-bit number in signed decimal fixed-point
// with resolution = 0.01 
// Input: SCI port, 16-bit signed number  -9999 to 9999
// Output: none
// fixed size, 6 characters, 4 digits of output, right justified
// if input is -1234, then display is -12.34 
void SCI_SOutFix2(unsigned char port, short num){ unsigned short n;
  if(num<0){ /* negative */
    n = -num;
    if(n < 10){
      SCI_OutString(port, " -0.0");
      SCI_OutChar(port, n+'0'); /* n is between 0 and 9 */
    } else if(n<100){
      SCI_OutString(port, " -0.");
      SCI_OutChar(port, n/10+'0'); /* tens digit */
      SCI_OutChar(port, n%10+'0'); /* ones digit */
    } else if(n<1000){
      SCI_OutString(port, " -");
      SCI_OutChar(port, n/100+'0'); /* hundreds digit */
      n = n%100;
      SCI_OutChar(port, '.');      /* decimal point */
      SCI_OutChar(port, n/10+'0'); /* tens digit */
      SCI_OutChar(port, n%10+'0'); /* ones digit */
    }
    else if(n<10000){
      SCI_OutChar(port, '-');   
      SCI_OutChar(port, n/1000+'0'); /* thousands digit */
      n = n%1000;
      SCI_OutChar(port, n/100+'0'); /* hundreds digit */
      n = n%100;
      SCI_OutChar(port, '.');      /* decimal point */
      SCI_OutChar(port, n/10+'0'); /* tens digit */
      SCI_OutChar(port, n%10+'0'); /* ones digit */
    }
    else {
    SCI_OutString(port, "-**.**");
    }
  } else{         /* positive */
    n = num;
    if(n < 10){
      SCI_OutString(port, "  0.0");
      SCI_OutChar(port, n+'0');      /* n is between 0 and 9 */
    } else if(n<100){
      SCI_OutString(port, "  0.");
      SCI_OutChar(port, n/10+'0');   /* tens digit */
      SCI_OutChar(port, n%10+'0');   /* ones digit */
    } else if(n<1000){
      SCI_OutString(port, "  ");
      SCI_OutChar(port, n/100+'0');  /* hundreds digit */
      n = n%100;
      SCI_OutChar(port, '.');        /* decimal point */
      SCI_OutChar(port, n/10+'0');   /* tens digit */
      SCI_OutChar(port, n%10+'0');   /* ones digit */
    }
    else if(n<10000){
     SCI_OutChar(port, ' ');   
      SCI_OutChar(port, n/1000+'0'); /* thousands digit */
      n = n%1000;
      SCI_OutChar(port, n/100+'0');  /* hundreds digit */
      n = n%100;
      SCI_OutChar(port, '.');      /* decimal point */
      SCI_OutChar(port, n/10+'0'); /* tens digit */
      SCI_OutChar(port, n%10+'0'); /* ones digit */
    }
    else {
      SCI_OutString(port, " **.**");
    } 
  }
}