I've tried the delay generator from piclist and I can't seem to get it working. It compiles without errors but the delay doesn't seem to work:
If however I use the following delay code from Nigels blinking lights tutorial it works fine:
Code:
LIST p=16F628 ;tell assembler what chip we are using
#include <p16F628.inc>
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _LVP_OFF & _BODEN_ON & _MCLRE_OFF
org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running
movlw 7
movwf CMCON
clrf PORTA
clrw
tris PORTA ; porta all output
clrf PORTB
movlw 0xf0
tris PORTB
bsf STATUS, RP0 ; bank 1
bcf OPTION_REG, NOT_RBPU ;internal pullups on port B enabled
bcf STATUS, RP0 ;bank 0
Loop
movlw 0xff
movwf PORTA ;set all bits on
movwf PORTB
call Delay
movlw 0x00
movwf PORTA ;set all bits on
movwf PORTB
call Delay
goto Loop
Delay
; Delay = 2 seconds
; Clock frequency = 4 MHz
; Actual delay = 2 seconds = 2000000 cycles
; Error = 0 %
cblock
d1
d2
d3
endc
;1999996 cycles
movlw 0x11
movwf d1
movlw 0x5D
movwf d2
movlw 0x05
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0
;4 cycles (including call)
return
end
If however I use the following delay code from Nigels blinking lights tutorial it works fine:
Code:
LIST p=16F628 ;tell assembler what chip we are using
#include <p16F628.inc>
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _LVP_OFF & _BODEN_ON & _MCLRE_OFF
cblock 0x20 ;start of general purpose registers
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
endc
org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running
movlw 7
movwf CMCON
clrf PORTA
clrw
tris PORTA ; porta all output
clrf PORTB
movlw 0xf0
tris PORTB
bsf STATUS, RP0 ; bank 1
bcf OPTION_REG, NOT_RBPU ;internal pullups on port B enabled
bcf STATUS, RP0 ;bank 0
Loop
movlw 0xff
movwf PORTA ;set all bits on
movwf PORTB
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay ; end of 2 secs
movlw 0x00
movwf PORTA ;set all bits on
movwf PORTB
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
call Delay
goto Loop
Delay movlw d'250' ;delay 250 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
end