I need a bit more clarity of delay routines.
how does this code implement a 104uS delay for RS232 serial data transfer using 4Hz clock?
Bit_Delay MOVLW 0x18
MOVWF Delay_Count
Bit_Wait NOP
DECFSZ Delay_Count , f
GOTO Bit_Wait
RETURN
Bit_Delay ; when called, this takes 2 instructions!
MOVLW 0x18 ; Moves literal value into Working reg. (1 instruction)
MOVWF Delay_Count ; Moves working reg contents into Variable (1 instruction)
Bit_Wait
NOP ; no operation. (1 instruction)
DECFSZ Delay_Count , f ; decrement 'Delay_Count (18Hex, 24 decimal) (1 instruction)
GOTO Bit_Wait ; goto bit wait. (2 instructions as its a program branch).
RETURN ; when done, go back to code. (1 instruciton I 'think').
So, the first part of it, under 'Bit_Delay' takes 2 cycles.
The second part is a loop, which is 4 cycles long (1, NOP + 1 for decfsz + 2 for goto). 'Bit_Wait' is executed until Delay_count is zero. So it loops 24 times (because 18hex is 24 in dec).
So..the loop is...4 * 24 = 96. Cycles long.
We 'call' the delay routine, which is a program branch and so takes 2 cycles. There are two further cycles at the start (under 'bit_Delay). So thats 4 at the start.
I think the 'return' part takes two instructions, maybe 1. We'll say 2 for now.
so..
Call = 2.
Pre-loop stuff = 2
Loop = 96
Return = 2
2+2+96+2 = 102. Not spot on but not bad. With a 4MHz osc, each instruction is 1us. Which makes delay calculations easy. So thats 102us. 104us is the period of a bit with a baud of 9600. (or half bit delay in 4800, used for the reciever). So the error in timing *IF* I'm correct is 102/104 = 1%. Thats fine.
Someone correct me if I'm wrong....its been a few months since I did PIC assembly, its all C over here now.
Blueteeth