i don't know which compiler you use but usually there is a delay library which includes delay_ms() and delay_us().
These use a loop method calculated with the cpu clock frequency and they are accurate if you don't use any interrupt while they execute,
if an interrupt executes then total delay will be the interrupt duration + delay function
The second method is to use a timer but you usually do this to repeat a function in specific intervals,
for example check if a key is pressed every 20 ms.
Alex