Hey again,
I've had a lot of help from the board in sorting out a Pedometer circuit I'm currently working on as part of a group project.
Unfortunately, we've been using the sprintf function to write the value of an integer 'noofsteps' into a character string, which was then written to the screen. Now that we've come to try and compile the completed code, it's too long to fit onto the chip (PIC16F684).
As suggested by members of this forum, I've looked at trying to accomplish what I'm trying to do without using sprintf (as I don't need anywhere near all of the functionality that sprintf allows).
Currently I'm trying to do the follow:
I have an integer called 'noofsteps', which will have a value between 0 and 20,000. I want to take the value of 'noofsteps' and display it on my LCD screen (Hitachi 44780) without using sprintf as it's too memory intensive.
I'm currently trying to implement this snippet I found elsewhere:
Code:
value = 12345; // number you want to display
length = 5; // five digits
div = 10000; // divisor
while( length )
{
lcd_write( (value / div) + 48 ); // write highest digit first
value = value % div;
length--;
div /= 10;
}
But as a complete beginner, I'm having trouble getting my head around how this could be integrated into the rest of the program.
I understand how this strips the integer number apart into its component numbers and then adds 48 so that each decimal number aligns to its ASCII equivalent.
However, what I don't understand is how I would write each number to my screen in sequence without removing the digit that was there before it. I.e. in this case, how to output "1", then shift the cursor on the screen to the right, then output "2", then shift the cursor to the right... etc. I'm guessing this information would be in the Hitachi 44780 Datasheet but I've got no clue how to find it, or even really what I'm looking for. For information, I am using the Hitachi 44780 in 4 BIT OPERATION.