I have a small project for a course I am doing that requires us to produce a PWM signal using PIC assembly language. To try and simplify things I have set the high time to 5ms and the low time to 15ms so I can call the same delay sub routine multiple times. Calling this delay multiple times seems to be causing the problem with the stack underflow.
I am not really sure what I can try to resolve this as I am very fresh to programming. I have tried searching on this site as well as generally but haven't been able to find a solution. I am using MPLab 9.82 as well.
The code is as follows:
list p=16F84A
#include <p16F84A.inc>
__CONFIG _CP_OFF & _XT_OSC & _PWRTE_ON & _WDT_OFF ;turn off watchdog timer
org 0x00 ; program starts at 0x00
counter equ 4Fh ; create a counter at position 4Fh in RAM
BSF STATUS, RP0 ; select bank 1
BCF TRISB, D'1' ; set port B pin 1 to output
BCF STATUS, RP0 ; select bank 0
goto main
main
BSF PORTB,1 ; turn port B pin 1 on
call delay_5ms ; calls sub routine for 5ms delay
BCF PORTB,1 ; turn port B pin 1 off
call delay_5ms ; calls sub routine for 5ms delay
call delay_5ms ; calls sub routine for 5ms delay
call delay_5ms ; calls sub routine for 5ms delay
delay_5ms
movlw D'200' ; put decimal number 200 into working register
movwf counter ; move 200 from working register into counter
lp nop ; no operation. just take 1 instruction
nop ; 1 instruction
decfsz counter ; 1 instruction and decreases counter by 1
goto lp ; 2 instructions (goto takes 2 instructions)
return
end