The way your timer1 function is written you have to ground PC5 and then PC4 to get to the actual timing part. You have to ground PC5 to get past this line:
while(bit_is_set(PINC, PINC5));//do nothing
And then you have to ground PC4 to get past this line:
while(bit_is_set(PINC, PINC4));//do nothing (timer 2)
If you wanted to start timing when either button is pressed, you could merge those two lines into something like:
while(bit_is_set(PINC, PINC5)&&bit_is_set(PINC, PINC4));
Or, if you wanted to start different timers for the different cases, you could do something like this:
while(1){
if(bit_is_clear(PINC, PINC5)){
timer1();
break;
}else if(bit_is_clear(PINC, PINC5)){
timer2();
break;
}
}
Also, inside your timer1 function, you have the line:
while(bit_is_set(PINC, PINC5)&bit_is_set(PINC, PINC4));
A single & is a bitwise and operation. In this case it may work the way you want it to depending on the return value of the bit_is_set function, but the header description of that function only says that it returns non-zero numbers when true, but not necessarily numbers that evaluate as true after a bitwise and operation. If that didn’t make any sense, don’t worry about it. What you really want to use is the logical and operator &&, as in if A and B are both true, then do something.
There are also a couple of methodology mistakes that might come back to byte you later. It’s usually not a great idea to call your main function at all, or create recursive function loops unless you really want to (like function A calls function B calls function A). It will rerun initialization functions you probably only want to run once, and it will create new copies of variables and state information that can fill up the free memory and lead to weird errors like stack overflows and things that are really hard to diagnose on a microcontroller. In this case your call to main at the end of the timer1 function is completely unnecessary, since the while(1) loop in main will keep calling the menu after timer1 returns.
One other quick mistake I see is that you’re referencing functions before you’ve created them, specifically you call the functions “menu” and “timer1” in main, but you don’t actually define them until later in the code. That why you’re getting those “implicit declaration of of function” warnings.
WinAVR seems to handle this for you, but generally in C you either need to order the functions so that you call them after you’ve written them, or write what are called function prototypes up at the top of the code. It’s sort of like an index, only at the beginning of the book. For simplicity a lot of people just like to put their “main” function at the very end of the code, which works fine too.
I know it sounds like a lot of problems, but it’s really just the simple mistakes that everyone makes. Your timer project is actually coming along quite nicely!
-Adam