Not to muddy the waters because it sounds like you have decided on another route, but for completeness ...
Code:
Start:
PortB.1 = 1 'Set pin high
@ NOP 'Wait....Two NOP's are neede if we want 50% dutycycle
@ NOP 'since the GOTO takes two instruction cylcles.
PortB.1 = 0 'Set pin low
Goto Start 'Do it again. The GOTO takes the same time as two NOP's
at 4 MHz, 3 instructions on and 3 instruction off = 6 instructions per cycle, therefore f=1000000/6=166666.667 Hz (twice that noted above)
Interestingly enough the above code does 3 instructions on and 4 instructions off on 16F devices and 3 on 3 off on 18F (at least on an 18F877A and 18F452, respectively). To combat this on the 16F's, you could do something like this in ASM
Code:
ASM
here
bsf PORTB,1
NOP
NOP
bcf PORTB, 1
goto here
ENDASM
Good Luck
Bookmarks