Hi Ken, >I have a project that I am about to start that requires some accurate timing >loops of odd lenghts. There is a basic program on the microchip BBS that will >generate the code for any lenght loop you need, but I also need to check for >some buttons being pressed while the loop is being exacuted. The program AW.BAS >does not do anything in the main loop and I can't see how to modify it to >include extra instruction. You'll need to add instructions to the inner loop like this: loop: decfsz r1 goto loop becomes (e.g. to test 1 bit with a button on) loop: btfsc ff, bb ; Replace ff & bb with bits to test goto buttonpress decfsz r1 goto loop and then redo the constants at the beginning of the program to reflect the longer inner loop. We've got a 5-cycle inner loop here, so the calculations become: tloop = 5 : REM Pulled out to a variable to ease mods x = delay - (13 + tloop): REM Minimum time through delay routine d = int(x/(((tloop*256 + 2)*256 + 2)*256 + 2)) x = x - d*(((tloop*256 + 2)*256 + 2)*256 + 2) c = int(x/((tloop*256 + 2)*256 + 2)) x = x - c*((tloop*256 + 2)*256 + 2) b = int(x/(tloop*256 + 2)) x = x - b*(tloop*256 + 2) a = int(x/tloop) x = tloop*a + (tloop*256+2)*b + ((tloop*256+2)*256+2)*c + (((tloop*256+2)*256+2)*256+2)*d + 8 a=a+1:b=b+1:c=c+1:d=d+1 The principle holds for longer inner loops (if, e.g. you wanted to test more than one bit.) Caveat emptor! I've not tested this, but it's a start at least. Dave