r/microcontrollers • u/Km6677 • Apr 08 '20
PIC microcontroller assignment
Hello, i have an assignment due I've spent 20 hours on and as a very beginner i am not very good at it. I have a project that is running almost correctly but there's an issue with the second loop. This code is for a microcontroller that uses and LCD and makes a timer go off. Its suppose to loop back to 0 at 23hrs 59minutes and 59 seconds. But for some reason the code will only loop back to 0 on the first run, the second run continues until 30 and then resets. Is there an easy fix for this in the for loop? PS. since the LCD can only run single digit numbers i just put th, tm and ts for tens of hours, minutes and seconds. **Please excuse the NESTED LOOPS i am made to use them i cannot use timers and counters**
https://gist.github.com/keaganm66/21e75f5df261ed17e919cffd48c0f602
2
u/ceojp Apr 09 '20
No idea. Those nested for loops are incomprehensible. You could simplify things by using the actual count(instead of having separate tens and ones loops). Then modulo 10(% operator) to get the tens place, and regular division to get the ones place.
This will also get you out of having to check for 23:59:59 within the for loops(which just makes everything that much more confusing). I think that's probably the source of your issues. In general you shouldn't reassign for loop variables or break out of for loops unless that is absolutely your only option, and in those cases there's usually a better option than using for loops.