I presume you are overwriting the existing declaration of main as:
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}
which would mean setup() isn't called, so you wouldn't be setting the pin to an output - meaning that you are seeing the LED as being on only because of the internal pullup resistor being enabled by digitalWrite(pin,HIGH).
It also means that init() is not being called, which means the micros() timer is not being setup, which means that delay() never counts meaning the program will freeze after:
digitalWrite(ledPin, HIGH);
Why are you trying to use main() instead of loop()? If you want the program to end just do this:
void loop(){
//you code
...
...
...
while(1); //end the program
}
or even this (if you want to save power):
#include <avr/sleep.h>
void loop(){
//you code
...
...
...
set_sleep_mode(SLEEP_MODE_PWR_DOWN); //least power consumption version of sleep.
sleep_enable(); //enable the ability to sleep.
cli(); //disable interrupts to prevent the avr from waking back up.
sleep_mode(); //put to sleep. no interrupts, so a power cycle would be required to wake it.
}