microcontroller - PIC184550: Program seems to terminate at call function -
i'm writing program blink red, yellow, , green leds off , on match function of traffic light. however, when run in debugger , step through (i using mplab x ide), seems stop after calling function 'loop1'. value reflected in portd value should hold after completion of loop1, rather after completion of loop6. ideas?
list p=18f4550, r=dec #include <p18f4550.inc> config lvp=off config wdt=off config mclre=off config fosc = intoscio_ec org 0x00 cblock 0 delay1:1 delay2:1 counter:1 endc start: clrf trisd clrf portd clrf counter clrf delay1 clrf delay2 movlw 0x00 primaryloop: call loop1 call loop2 call loop3 call loop4 call loop5 call loop6 goto primaryloop loop1: movlw b'00010010' movwf portd movlw 0x01 movwf counter call delaymain return loop2: movlw b'01000010' movwf portd movlw 0x05 movwf counter call delaymain return loop3: movlw b'00100010' movwf portd movlw 0x03 movwf counter call delaymain return loop4: movlw b'00010010' movwf portd movlw 0x01 movwf counter call delaymain return loop5: movlw b'01000010' movwf portd movlw 0x05 movwf counter call delaymain return loop6: movlw b'00100010' movwf portd movlw 0x03 movwf counter call delaymain return delaymain: decfsz delay1,1 goto delaymain decfsz delay2,1 goto delaymain decfsz counter,0,0 return end
you're skipping return instruction in delaymain, causing execution go beyond program. rest of memory contains nop
instructions, control continue until pc wraps around 0 , program restarts.
simply add missing goto
(or bra
) instruction after last decfsz
, should second loop. need change destination of decfsz
write register, or never finish when counter > 1
.