Conversions for the LCD display in FRDM-KL46Z
Dependents: eem202a_display eem202a_resolutedreamer_1
Diff: convert.cpp
- Revision:
- 2:9467805cb02b
- Parent:
- 1:cf83568dc17a
- Child:
- 3:551fe797c723
diff -r cf83568dc17a -r 9467805cb02b convert.cpp --- a/convert.cpp Sat Apr 19 17:42:24 2014 +0000 +++ b/convert.cpp Sat Apr 19 22:07:19 2014 +0000 @@ -1,5 +1,11 @@ #include "convert.h" +/*------------------------------------------------------------- + +(c) W.D. 2014 + +-------------------------------------------------------------*/ + Convert::Convert() { this->prepare(); @@ -20,7 +26,7 @@ return; } -bool Convert::display_digits(unsigned int number, bool negate) +void Convert::display_digits(unsigned int number, bool negate) { register unsigned short int c1 = ((unsigned int) number / 1000); register unsigned short int c2 = ((unsigned int) number / 100) - (c1 * 10); @@ -37,64 +43,81 @@ this->putc('0'+c3); this->putc('0'+c4); - return false; + return; } bool Convert::display(unsigned int number) { + this->DP1(false); + this->DP2(false); + this->DP3(false); + this->Colon(false); + if (number > 9999) { - this->Home(); this->blink(2); - this->putc(' '); - this->putc('O'); - this->putc('F'); - this->putc('L'); + this->display(" OFL"); return true; } else { this->display_digits(number); + return false; } - return false; } bool Convert::display(int number) { - bool negate = (number < 0); - if (negate) + this->DP1(false); + this->DP2(false); + this->DP3(false); + this->Colon(false); + + if (number < 0) { if (number < -999) { - this->Home(); this->blink(3); - this->putc('-'); - this->putc('O'); - this->putc('F'); - this->putc('L'); + this->display("-OFL"); return true; } else { - return this->display_digits ((unsigned int) -number, negate); + this->display_digits ((unsigned int) -number, true); + return false; } } + else if (number > 9999) + { + this->blink(3); + this->display(" OFL"); + return true; + } else { - return this->display ((unsigned int) number); + this->display_digits ((unsigned int) number, false); + return false; } } bool Convert::display(double number) { + this->Colon(false); // >=10000 OVL + if (number >= 10000.) + { + this->blink(3); + this->display(" OFL"); + return true; + } // >=1000 1234 - if (number >= 1000.) + else if (number >= 1000.) { this->DP1(false); this->DP2(false); this->DP3(false); - return this->display((unsigned int) (number)); + this->display_digits ((unsigned int) number); + return false; } // >=100 123.4 else if (number >= 100.) @@ -102,7 +125,8 @@ this->DP1(false); this->DP2(false); this->DP3(true); - return this->display((unsigned int) (number*10.)); + this->display_digits ((unsigned int) number*10.); + return false; } // >=10 12.34 else if (number >= 10.) @@ -110,7 +134,8 @@ this->DP1(false); this->DP2(true); this->DP3(false); - return this->display((unsigned int) (number*100.)); + this->display_digits ((unsigned int) number*100.); + return false; } // >=0 1.234 else if (number >= 0.) @@ -118,51 +143,65 @@ this->DP1(true); this->DP2(false); this->DP3(false); - return this->display((int) (number*1000.)); + this->display_digits ((unsigned int) number*1000.); + return false; } // <0 // <=-1 -1.23 -// <=-10 -12.3 else if (number >= -10.) { this->DP1(false); this->DP2(true); this->DP3(false); - return this->display((int) (number*100.)); + this->display_digits ((unsigned int) number*-100., true); + return false; } -// <=-100 -123 +// <=-10 -12.3 else if (number >= -100.) { this->DP1(false); this->DP2(false); this->DP3(true); - return this->display((int) (number*10.)); + this->display_digits ((unsigned int) number*-10., true); + return false; } - else +// <=-100 -123 + else if (number >= -1000.) { this->DP1(false); this->DP2(false); this->DP3(false); - return this->display((int) (number*1.)); - }; + this->display_digits ((unsigned int) -number, true); + return false; + } + else // <=-1000 -OVL + { + this->blink(3); + this->display("-OFL"); + return true; + } - return true; } bool Convert::display(float number) { - return display((double) number); + return this->display((double) number); } -bool Convert::display(char text[4]) +bool Convert::display(char *text) { this->DP1(false); this->DP2(false); this->DP3(false); - this->putc(text[0]); - this->putc(text[1]); - this->putc(text[2]); - this->putc(text[3]); + this->Colon(false); + this->Home(); + for(int i=0; i<4; i++) + { + if (text[i]==0) + break; + else + this->putc(text[i]); + } return false; }