So I just started learning about PIC microcontrollers starting with the 8-bit PIC16F84A. I have written a simple code that blinks an LED and I wanted to ask something. Here is a segment of the code that turns on the LED and waits. What I wanted to ask is that in the loop it counts to 255, 255 times. If one instruction takes 1uS to execute then the whole loop takes a time of 255*255*(1E-06)=65ms. But when I simulate the same program in Proteus, it shows that the LED stays on for 198ms and not 65ms. What could I be doing wrong?
Your loop takes 3 instruction cycles to execute. Not every instruction on the PIC takes exactly one instruction cycle. See Table 7-2 in the PIC16F84A datasheet.
DECFSZ takes 1 instruction cycle usually (2 when it skips) and
GOTO takes 2 instruction cycles. That's 3 cycles normally. So, given 3uS per loop, that's almost exactly the timing you got (196ms). The extra time probably comes from the 5 cycles that the loop takes when COUNT1 underflows and the 4 cycles in the very last loop cycle.