Hi! First, your code gets executed 255 times (0xFF) in a loop. When done, it doesn't stop like you want it to, instead it goes straight on to subprocedure1. When it gets to RETURN command, stack underflow occurs-processor doesn't have an address on stack to return anywhere. In MPLAB SIM you get an warning for that, in reality I don't know what happens. You should put an neverending loop at the end of your code to cure that. As for constant repeating, maybe you have WDT set to ON and PIC keeps reseting itself.One more thing: it would help a great deal also to you if you'd put some comments to your code.Regards, Samo CURE for first problem: movlw 0xFF ;you want 50 here, not 255 movwf counter loop: BCF porta,01 CALL pulse BSF porta,01 CALL farve_1 BCF porta,01 decfsz counter goto loop BCF porta,01 STOP goto STOP ;loop here forever ; ; ; ===== Subprocedure 1 ===== farve_1 clrf mcount clrf ecount movlw 0x09 movwf mcount l1 movlw 0x19 movwf ecount d1 decfsz ecount,f goto d1 decfsz mcount,f goto l1 clrf mcount movlw 0x1B movwf mcount a1 decfsz mcount,f goto a1 NOP NOP NOP NOP NOP return ; ; ===== Subprocedure 2 ===== pulse clrf ncount clrf count movlw 0x52 movwf count loadn movlw 0x50 movwf ncount decn decfsz ncount,f goto decn decfsz count,f goto loadn return ; end -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Lasse Madsen Sent: Sunday, September 23, 2001 11:08 PM To: PICLIST@MITVMA.MIT.EDU Subject: [PIC]: Please help me before i loose sanity :) Hi All I have used the code that Anders M. J. send me and modified my own code with it BUT it doesnt work ! What i want the below code to do is: do the "thing" 50 times (0x32 in hex) and do nothing (end program) BUT: The program keeps repeating it self to infinity and i didnt specify that anywhere (i think) Please help me. Best regards lasse madsen list p=16f84 radix hex porta equ 0x05 org 0x000 start movlw 0x00 tris porta ecount equ 0x0c ncount equ 0x0d mcount equ 0x0e count equ 0x1a counter equ 0x1b ; ; movlw 0xFF movwf counter loop: BCF porta,01 CALL pulse BSF porta,01 CALL farve_1 BCF porta,01 decfsz counter goto loop BCF porta,01 ; ; ; ===== Subprocedure 1 ===== farve_1 clrf mcount clrf ecount movlw 0x09 movwf mcount l1 movlw 0x19 movwf ecount d1 decfsz ecount,f goto d1 decfsz mcount,f goto l1 clrf mcount movlw 0x1B movwf mcount a1 decfsz mcount,f goto a1 NOP NOP NOP NOP NOP return ; ; ===== Subprocedure 2 ===== pulse clrf ncount clrf count movlw 0x52 movwf count loadn movlw 0x50 movwf ncount decn decfsz ncount,f goto decn decfsz count,f goto loadn return ; end -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads