Hi;
I would like to ask you that I want to calculate the time to execute each instruction of simple example bellow that I wrote on miKroC for atmega32 and Device clock of 1.000000MHz, maybe some instruction takes more time than other like while or if ?
Thanks
void main() {
void init();
/* Configure the ports as output */
DDRB = 0xff;
while(1)
{
PORTB =(1<< PINB1);
Delay_ms(1000);
PORTB&= ~(1<< PINB1);
}
}
What the previous poster said if you really want the exact answer. However, it's going to look something like this:
while(1){ // top of loop, no condition to evaluate so no code: 0 cycles
PORTB =(1<< PINB1); // simple write port: 1 cycle
Delay_ms(1000); // call delay routine: approximately 1,000,000 cycles
PORTB&= ~(1<< PINB1); // AND to port: 2-3 cycles, depending on how smart the compiler optimization is for changing a single bit.
} // jump to top of loop: 2 cycles
So PINB1 will be ON for ~1000003 cycles, OFF for 3 cycles, ON for ~1000003 cycles, OFF for 3 cycles, etc, giving you a 3 microsecond blip on the port every second. Which could be shorter than the rise/fall time on the output pin, depending on what you've got connected in the way of pull-up resistors and such. You'd need a scope to see it in any case.