Pleas let me know how should I write so that the increment would be by 2. I understand that this code will increment the value of cnt++ by one up to 255. Help me make it by two's please, THanks
if (kp != oldstate) { // Pressed key differs from previous
cnt = 1;
oldstate = kp;
}
else { // Pressed key is same as previous
cnt++;
}
Lcd_Chr(1, 10, kp); // Print key ASCII value on LCD
if (cnt == 255) { // If counter varialble overflow
cnt = 0;
Lcd_Out(2, 10, " ");
}
WordToStr(m, txt); // Transform counter value to string
Lcd_Out(2, 10, txt);
That will work if cnt is a 16 bit (or more) variable, not if it's an 8 bit, since it will never be more than 255 and will roll over from 254 to 0, missing the test again.
That will work if cnt is a 16 bit (or more) variable, not if it's an 8 bit, since it will never be more than 255 and will roll over from 254 to 0, missing the test again.