Hi,
For blinking a LED I recommend to use a timer, too.
* the timer solution is more flexible and useful
* the timer solution is more exact
* the timer solution needs about no processing power (your solution needs 100% of processing power, it makes it difficult for the microcontroller to react on any other events, like key press)
But back to your solution. A busy wait.
In general...
* any instruction needs exactely n crystal clock cycles (it depends on the instruction and the clock system)to process.
Read datasheet.. how many clock cycle each instruction takes.
Now let's say you want the LED to blink 400ms ON, 400ms OFF. Clock is 11.0592 MHz.
Then multiply the 11,509,200 Hz with 0.4s and get 4,423,680 clock ticks.
You need to program a loop that takes 4.4 million clock cycles to be processed.
In assembly you need nested loops.
To me more useful I recommend to use a one byte parameter to select the delay time.
In your case maybe 10ms steps. So you are able to flexiby generate delay times from 10ms up to 2560ms.
A 400ms delay then acts as a 40 x 10ms delay.
Then the outer loop counts (parameter: 40) how often the 10ms inner loop is beeing processed.
The inner loop = 10ms = 110592 clock ticks.
Because the "110592" is that big an 1 byte loop is not sufficient. I assume you need two counters for thd inner loop.
A loop consists of
* a variable that is incremented (lets say 4 clock cycles)
* a compare (lets say 4 clock cycles)
* a conditional jump (lets say 12clock cycles)
So one loop takes a total of 4 + 4 + 12 = 20 clock cycles
Now use one variable as 256 loop counter. 256 x 20 clock cycles = 5120 clock cycles (463 us)
110592 / 5120 = 21.6 ..... use 22
--> Use one variable to count 22 loops (of 463us each) to get about 10ms.
--> 40 x 22 x 256 x 20 = about 4.5 million clock ticks = about 407.4ms.
(It's possible to get more precise 400ms .... but for blinking a LED....)
Klaus