On Sun, 9 Nov 1997 23:00:37 +0200 Kevin Howell writes: > I need some math routines for the Pic 16c84 >. The answer to these math routines will all be real numbers in other >something like 3.123. I need a way to split everything after the comma >and before to display them as whole numbers on screen! >e.g. 10/2=5 thats easy using multiple subtracting routines, but what >about 11/3 ???? Consider BCD long division, as used to be done in grade school. Results will be "exact" and processing not too complicated as long as the denominator is only a couple of digits. If you'd like a fixed number of digits after the decimal point, use binary math and scale everything by a power of 10, for example compute 11/3 as 11000/3000 = 3666 (or 3667 if rounded up), display as 3.666. > > >Then also I am busy with a rev counter with lcd, how do you display a >changing number on a lcd. How do I split all the digits up to display >them character by character.e.g 1200 , first display the 1 then the 2 >next to it and so on. The HD44780 displays can be set to display right to left, allowing the PIC to divide the number by 10 repeatedly and display the remainder without having to store the digits. For example: 1234 / 10 = 123 remainder 4 - print 4 123/10 = 12 remainder 3 - print 3 12/10 = 1 remainder 2 - print 2 1/10 = 0 remainder 1 - print 1 Since the display is printing right to left, the digits appear in proper order: "1234". The process can stop when the result is 0. If you don't want to use this "trick" mode, store the digits in RAM then output in the proper order (this takes more RAM obviously). The divide routine can be reused for other computations, so the "output in BCD" doesn't have to take a lot of space. Microchip application note AN554 has a different method for converting that should be considered for larger numbers such as 24 or 32 bits. For numbers of 8 or maybe 16 bits there are tricks that have been discussed here before but they get more and more complicated as the allowable maximum value of the number increases.