If all you need is a simple delay, here's what I use: Small delay, up to 769 cycles: movlw n ;}1 cycle movwf TEMP ;}1 cycle decfsz TEMP ;/\ goto $-1 ;__> 3n-1 cycles c=3n+1 where: c = cycles n = literal at first instruction, 1 =< n =< 256 (0x001 =< n =< 0x0100, where 0x000=0x0100) Nested delay, unlimited cycles: movlw n ;}1 cycle movwf TEMP ;}1 cycle loop (nested delay loop) ;/\ decfsz TEMP ; > nd+3n-1 cycles goto loop ;_/ c=nd+3n+1 where: c = cycles n = literal at first instruction, 1 =< n =< 256 (0x001 =< n =< 0x0100, where 0x000=0x0100) d = number of cycles in nested delay loop To calculate the length of delay, find the number of instruction cycles it will complete, and divide that by the number of instructions per second your PIC is running at (equal to the frequency of the internal oscillator divided by four). Chances are you will have to use a nested loop if what your are doing is a visual effect, where you can just plug in the first delay above into the second (max 197,633 cycles, about 2ms at 4MHz). If more cycles were needed, you could then take this delay, and nest it once again in another loop (max 50,594,817 cycles, about 51s at 4MHz, just make sure that the TEMP register is different in each loop. If all you are doing is blinking lights, delays this long will not matter, but in other applications this would be a considerable amount of dead potential processing time, and other methods of timing would be used. For more time critical applications, if there are no possible combinations of literals to get the exact number of cycles you need, you would simply find the combination with the closest number of cycles possible below the desired number, then add a few nop's. --Nick --- Michael Johnston wrote: > Hi guys > I wrote a program that i adaptive with help from a > friend to flash 12 leds tied to the 12 I/O Pins on > c54. I have four routines that rotate the bit > pattern through porta and portb forwards and > backwards. My problem is that when the routine is > going from porta to portb forward ra3 flashes so > fast and jumps to portb bit0 so fast you can not see > this happening. It also does this when going > backwards from portb to porta. But it portb bit 7 > that you dont see flashing. My friend told me the > reason this was happening was because of the part i > am using so i ported it to F84 and the program did > the same thing in this port. I need so type of a > delay but everything i try seems to mess my code up. > Thanks > Mike Johnston > > -- > http://www.piclist.com hint: To leave the PICList > mailto:piclist-unsubscribe-request@mitvma.mit.edu __________________________________ Do you Yahoo!? Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes http://hotjobs.sweepstakes.yahoo.com/signingbonus -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads