Hi i am after some help with my code i have timed six ports to drive an ultra sonic transducer at 40K i just need a hand stopping timer0 and getting the data back here is my current codeCode:LIST p=16F877 ;tell assembler what chip we are using include "P16F877.inc" ;include the defaults for the chip __config 0x3D18 ;sets the configuration settings (oscillator type etc.) cblock 0x20 ;start of general purpose registers count1 ;used in delay routine counta ;used in delay routine countb ;used in delay routine endc cblock d1 endc LEDPORT Equ PORTB ;set constant LEDPORT = 'PORTB' LEDTRIS Equ TRISB ;set constant for TRIS register org 0x0000 ;org sets the origin, 0x0000 for the 16F628, ;this is where the program starts running movlw 0x07 Loop call One call Two call Three call Four call Five call Six goto Loop ;go back and do it again One movlw b'10000000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'10000000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'10000000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'10000000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'10000000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'10000000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! Return Two movlw b'01000000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'01000000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'01000000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'01000000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'01000000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'01000000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! Return Three movlw b'00100000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00100000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00100000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00100000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00100000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00100000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! Return Four movlw b'00010000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00010000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00010000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00010000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00010000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00010000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! return Five movlw b'00001000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00001000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00001000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00001000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00001000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00001000' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! return Six movlw b'00000100' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00000100' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00000100' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00000100' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00000100' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! movlw b'00000100' movwf LEDPORT call DelayMark ;this waits for the marktime! movlw b'00000000' movwf LEDPORT call DelaySpace ;this waits for spacetime! return DelayMark ;58 cycles movlw 0x13 movwf d1 DelayMark_0 decfsz d1, f goto DelayMark_0 ;1 cycle nop ;4 cycles (including call) return ; Delay = 62 instruction cycles ; Clock frequency = 20 MHz ; Actual delay = 1.24e-005 seconds = 62 cycles ; Error = 0 % cblock c1 endc DelaySpace ;58 cycles movlw 0x13 movwf c1 DelaySpace_0 decfsz c1, f goto DelaySpace_0 ;4 cycles (including call) return end could some one help me take the next step i cant use the interrupt to stop the 877 im using the int pin for something else and it is already connected on hardware so i need to check for a return but really quick also how do i do multiplication as i need to times the result by 340 m/s to give me the distance between the senser and the target then divide by two but i can over come this thanks

Reply With Quote