In addition to the other replies, there's a couple of points I want to add:
-
You need to comment your code - for example, what the heck are each of those #defines for? I don't know; I suspect you'll forget, too, when you come back to the code in a few years (trust me, you'll come back).
-
I also see waaaay too many "magic numbers"! What are "magic numbers"? Magic numbers are numbers scattered throughout code without explanation; it kinda relates to my first item, too. These numbers should be declared as #define or constants of some sort, and should have well thought out variable names, and/or should be commented as to what (and why) the numbers are for. Again - when you come back to the code in a few years, you'll be grateful you did so.
Trust me on both of these: For almost any code you write, you'll be supporting it until the end of time. If you aren't supporting it, /someone else will be/! That "someone else" might very well be a "future you" who has forgotten what the code does and why. If you don't keep any documentation on it (especially in the code!), you'll sit there wondering what the hell was going on when you wrote it, and likely will end up scrapping it, and re-doing it (even if the code was perfectly fine, logically, to begin with). Thereby, wasting not only your (or someone else's) time "now", but your (or their) time "then" as well.
Do all of us software developers a favor. Comment your code. Eliminate "magic numbers". We'll all be grateful.
/if I had a nickle for every time I've seen both of these abuses in my career...