If you're going to convert this to produce the same timing at 4MHz, you'll
need to use an assembler delay routine.
At 20MHz, like the original C version, delay_cycles(59); gives you a delay of
59 * 200nS instruction cycles. 59 * 200nS = 11.8uS.
PAUSEUS at 4MHz is limited to a minimum delay period of 24uS, and with an
instruction time of 1uS at 4MHz, you're still going to be off by a minimum of
200nS.
12uS is about as close as you can get to the original 11.8uS delay period.
Code:
' For 4MHz use XT_OSC
@ DEVICE PIC16F84A, XT_OSC,WDT_OFF,PROTECT_OFF,PWRT_ON
DEFINE OSC 4
ltime VAR BYTE
GOTO Main
PAUSE12: ' CALL to here = 2uS
ASM
GOTO $+1 ; 2uS
GOTO $+1 ; 2uS
GOTO $+1 ; 2uS
GOTO $+1 ; 2uS
RETURN ; 2uS (12uS total delay time)
ENDASM
Main:
TRISB = 0
FOR ltime = 0 TO 49 ' 50 loops total
PORTB.7 = 1
PAUSE 50
PORTB.7 = 0
PAUSE 50
NEXT ltime
WHILE (1)
PORTB = 1
CALL PAUSE12
PORTB = 2
CALL PAUSE12
PORTB = $41
CALL PAUSE12
PORTB = $42
CALL PAUSE12
WEND
END
This would give you very close to the same program & timing. The difference
is the delay between port updates in the WHILE loop are 12uS VS 11.8uS.
Bookmarks