Hi,
I'm trying to call a delay of 25mS and I have googled and found a couple of websites with tutorials explaining delays, most of their delays look something like this:
The problem is that when I call a 25mS delay (I edited the delay routine I found here: MPASM Tutorial - Using Switches | MPASM Assembly) it just stalls, and never exits the delay. When I run the animate debug mode, I can see it keeps on looping here:
It skips the "goto $+2" and then jumps back up to "decfsz counter2, f" when it reaches "goto $-3".
This code:
From another site, does exactly the same thing...
I'm not sure why this is the way the delay routine is set up, I've seen it like this in a couple of places, but it just does not work!
...driving me nuts!
This works though... but the delay is roughly 140mS.
Was just experimenting and it worked. But if I change "movlw .1" to ".25" ... it stalls again... ???
Thanks in advance?
For those interested:
Here is the entire .asm file - maybe you can spot where my mistake is.
I had the delays between ISR and Main, but put it last since I thought it might make a difference.
I'm trying to call a delay of 25mS and I have googled and found a couple of websites with tutorials explaining delays, most of their delays look something like this:
Code:
_0mS
retlw 0x00 ;delay 0mS - return immediately
_1mS
movlw d'1' ;delay 1mS
goto Delay
_5mS
movlw d'5' ;delay 5mS
goto Delay
_10mS
movlw d'10' ;delay 10mS
goto Delay
_20mS
movlw d'20' ;delay 20mS
goto Delay
_25mS
movlw d'25' ;delay 25mS
goto Delay
_50mS
movlw d'50' ;delay 50mS
goto Delay
_100mS
movlw d'100' ;delay 100mS
goto Delay
_250mS
movlw d'250' ;delay 250 ms
goto Delay
Delay
movwf counter0
d1 movlw 0xC7 ;delay 1mS
movwf counter1
movlw 0x01
movwf counter2
decfsz counter2, f
goto $+2
decfsz counter2, f
goto $-3
decfsz counter0 ,f
goto d1
retlw 0x00
The problem is that when I call a 25mS delay (I edited the delay routine I found here: MPASM Tutorial - Using Switches | MPASM Assembly) it just stalls, and never exits the delay. When I run the animate debug mode, I can see it keeps on looping here:
Code:
decfsz counter2, f
goto $+2
decfsz counter2, f
goto $-3
This code:
Code:
_10mS
movlw 0Ah
movwf temp2
nop
decfsz temp1,f
goto $-2
decfsz temp2,f
goto $-4
retlw 00
From another site, does exactly the same thing...
I'm not sure why this is the way the delay routine is set up, I've seen it like this in a couple of places, but it just does not work!
...driving me nuts!
This works though... but the delay is roughly 140mS.
Was just experimenting and it worked. But if I change "movlw .1" to ".25" ... it stalls again... ???
Code:
_25mS
movlw .1
movwf counter0
nop
decfsz counter1,f
goto $-2
decfsz counter0,f
goto $-4
retlw 00
Thanks in advance?
For those interested:
Here is the entire .asm file - maybe you can spot where my mistake is.
I had the delays between ISR and Main, but put it last since I thought it might make a difference.
Code:
;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------
LIST p=16F88 ; list directive to define processor
#INCLUDE <P16F88.INC> ; processor specific variable definitions
;------------------------------------------------------------------------------
; CONFIGURATION WORD SETUP
;------------------------------------------------------------------------------
__CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_OFF & _WDT_OFF & _INTRC_IO
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
;------------------------------------------------------------------------------
; VARIABLE DEFINITIONS
;------------------------------------------------------------------------------
CBLOCK 0x20 ; Sample GPR variable registers allocated contiguously
counter0 ; User variable
counter1 ; User variable
counter2 ; User variable
ENDC
W_TEMP EQU 0x7D ; w register for context saving (ACCESS)
STATUS_TEMP EQU 0x7E ; status used for context saving (ACCESS)
PCLATH_TEMP EQU 0x7F ; variable used for context saving
;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;------------------------------------------------------------------------------
DATAEE ORG 0x2100
DE "MCHP" ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3
;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------
RESET ORG 0x0000 ; processor reset vector
PAGESEL START
GOTO START ; go to beginning of program
;------------------------------------------------------------------------------
; INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------
ISR ORG 0x0004 ; interrupt vector location
; Context saving for ISR
MOVWF W_TEMP ; save off current W register contents
MOVF STATUS,W ; move status register into W register
MOVWF STATUS_TEMP ; save off contents of STATUS register
MOVF PCLATH,W ; move pclath register into W register
MOVWF PCLATH_TEMP ; save off contents of PCLATH register
;------------------------------------------------------------------------------
; USER INTERRUPT SERVICE ROUTINE GOES HERE
;------------------------------------------------------------------------------
; Restore context before returning from interrupt
MOVF PCLATH_TEMP,W ; retrieve copy of PCLATH register
MOVWF PCLATH ; restore pre-isr PCLATH register contents
MOVF STATUS_TEMP,W ; retrieve copy of STATUS register
MOVWF STATUS ; restore pre-isr STATUS register contents
SWAPF W_TEMP,F
SWAPF W_TEMP,W ; restore pre-isr W register contents
RETFIE ; return from interrupt
;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------
START
TURNA equ b'00000001'
TURNB equ b'00000010'
TURNC equ b'00001000'
TURND equ b'00010000'
banksel TRISB
movlw b'11100100' ;Set bits 0,1,3,4 as outputs 2 give weird signal
movwf TRISB
banksel PORTB
loop
movlw TURNA
movwf PORTB
call _25mS
movlw TURNB
movwf PORTB
call _25mS
movlw TURNC
movwf PORTB
call _25mS
movlw TURND
movwf PORTB
call _25mS
goto loop
;-----------;
;---Delay---;
;-----------;
_0mS
retlw 0x00 ;delay 0mS - return immediately
_1mS
movlw d'1' ;delay 1mS
goto Delay
_5mS
movlw d'5' ;delay 5mS
goto Delay
_10mS
movlw d'10' ;delay 10mS
goto Delay
_20mS
movlw d'20' ;delay 20mS
goto Delay
_25mS
movlw d'25' ;delay 25mS
goto Delay
_50mS
movlw d'50' ;delay 50mS
goto Delay
_100mS
movlw d'100' ;delay 100mS
goto Delay
_250mS
movlw d'250' ;delay 250 ms
goto Delay
Delay
movwf counter0
d1 movlw 0x00 ;delay 1mS
movwf counter1
movlw 0x00
movwf counter2
decfsz counter2, f
goto $+2
decfsz counter2, f
goto $-3
decfsz counter0 ,f
goto d1
retlw 0x00
END