nimblemotors 23 Posted December 11, 2011 Share Posted December 11, 2011 I have do this often for my LCD display output, and wrote a routine called BCDdecode that does it for 3 digits, and then returns the remainder so it can work for more digits if needed. And also note if d3 is zero, it is just doing two digits unsigned short BCDecode(unsigned short val, unsigned char *d1, unsigned char *d2, unsigned char *d3) { *d1 = val % 10; val = val / 10; *d2 = val % 10; val = val / 10; if (d3) { *d3 = val % 10; val = val / 10; } return val; } // and example use to display temp LCDout_temp (unsigned short temp) { unsigned short val = temp; char d1,d2,d3,d4; BCDecode(val, &d1, &d2, &d3); if (d3 > 0) { LCDdigit(d3); } else { LCDout(1, ' '); } LCDdigit(d2); LCDdigit(d1); LCDout(1, 'F'); } bluehash 1 Quote Link to post Share on other sites
bluehash 1,581 Posted December 18, 2011 Share Posted December 18, 2011 Nice sounds SimpleAVR and thanks for sharing your code nimblemotors. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.