If you look at button increment routine you have two tests for button == 1,
so both incrementing sections increment when a button is pressed, and
both times the cursor position is changed, independent of the "value" of
what is going on in the digit cursor is pointing to.
This is a classic case where you should do a decision flow chart so you can
visualize the code and its decision paths.
Also your braces in the code are not right. Your second section of code under
and "if(temp > 57) temp = 48; " missing in second section ?
So should look like this -
Code:
void incrementbutton(void) {
if (button == 1) {
set_cursor_position (1, 2);
if (temp >= 47 && temp < 57) {
temp = temp+1;
}
if(temp > 57) temp = 48;
set_cursor_position (1, 2);
upf = 0;
}
}
if(button == 1) {
set_cursor_position(1,3);
if (temp1 >= 47 && temp1 < 57) {
temp1 = temp1 +1;
}
if(temp > 57) temp = 48;
set_cursor_position(1,3); << What should you do here ?
upf = 0;
}
}
}
Aboive still not right because when button is pressed both sections of code
always execute, which I do not think you want. In other words there is no variable
telling you what cursor digit you are working on so you only apply the button
press to that digit, and when it hits 9 and you want to inc then you test for digit overflow,
reset digit, AND then move to next cursor position and inc that digit.....
So I think you have two decision tree, inc current digit at cursor location, then test if
it was 9 and now needs to be 0 and move to next cursor position and force an inc to
that position. If initial digit was < 9 before inc, then inc that digit and leave cursor position
unchanged ? Right.....?
Flow charts are great for revealing these problems.
Regards, Dana.