ATMega16: Run a subroutine for a limited time
There are plenty of ways you could do something like this. Assuming you're using AVR gcc, you could use the utility functions in util/delay.h,  specifically _delay_ms() would be applicable for your requirement. You can find the documentation at www.nongnu.org/avr-libc/user-manual/group_util_delay.html.  Note, however, that there is a maximum delay that you can generate using these functions,  depending on your clock speed. If you want to delay for longer, then you'll have to use some sort of a loop that calls it repeatedly. The typical way to use it in your case would be to do what your function has, then delay, and then disable your motors and such. There are some disadvantages to using this method, though. First, these delays are essentially for loops simply looping around for some number of iterations. This means that they aren't exactly accurate. Also,  any interrupts that may be happening will cause this time to stretch. 

When writing firmware it is often best to avoid using these kinds of delays. Not only are they inaccurate,  they are also blocking calls. For the duration of the delay, the processor can't run any other code (unless from within an interrupt, which throws off the delay). There are better ways to solve your problem, but they do need more work. One way is to configure a timer to interrupt after the time you require, and then use code that is called by the interrupt handler to stop the motor. The 'good' way to do this would be to set a flag inside the interrupt and have the main loop check for this flag. This way, the main loop can keep tabs on multiple things in parallel and execute code at the correct time. 

More complicated systems could use an RTOS to do this, but they often come with more baggage than is worthwhile unless you really need high precision and have many different things that have to happen in parallel.