dim x as word
for x = 1 to 60000
delay_ms(1080)
next x
i want to use assembly language , mplab programWhich language and compiler do you use?
In mikroBASIC we could do something like:
Code:dim x as word for x = 1 to 60000 delay_ms(1080) next x
That's a delay of 1.08 seconds 60000 times = 64800s = 1080mins = 18 hours
In mikroC, we'd do something similar.
Hope this helps.
Tahmid.
; Delay = 64800 seconds
; Clock frequency = 4 MHz
; Actual delay = 64800 seconds = 64800000000 cycles
; Error = 0 %
cblock
d1
d2
d3
d4
d5
endc
Delay
;64799999988 cycles
movlw 0xA1
movwf d1
movlw 0x24
movwf d2
movlw 0x21
movwf d3
movlw 0x60
movwf d4
movlw 0x02
movwf d5
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto $+2
decfsz d4, f
goto $+2
decfsz d5, f
goto Delay_0
;8 cycles
goto $+1
goto $+1
goto $+1
goto $+1
;4 cycles (including call)
return
here: goto $
here:
bsf portb,1
bsf portb,2
goto $+2
bsf portb,3
bsf portb,4
goto $-5
can you please explain for me how you calculated number of cycles and the value of delay??Hi,
In that case, use the timer as keith suggested to get the longest delay. Calculate how long the delay is and according keep a seconds register that increments and resets accordingly in the process incrementing a minutes and an hours registers. When the value in the hours registers = 18, stop the timer and go on doing whatever you would.
Alternately a simpler method is the delay routine:
Code:; Delay = 64800 seconds ; Clock frequency = 4 MHz ; Actual delay = 64800 seconds = 64800000000 cycles ; Error = 0 % cblock d1 d2 d3 d4 d5 endc Delay ;64799999988 cycles movlw 0xA1 movwf d1 movlw 0x24 movwf d2 movlw 0x21 movwf d3 movlw 0x60 movwf d4 movlw 0x02 movwf d5 Delay_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto $+2 decfsz d4, f goto $+2 decfsz d5, f goto Delay_0 ;8 cycles goto $+1 goto $+1 goto $+1 goto $+1 ;4 cycles (including call) return
Hope this helps.
Tahmid.
first bsf 03,5
first bsf STAUS, 5
first bsf STAUS, RP0
clrf 85 ; 85 and 86 are trisa, trisb
clrf TRISA
PROCESSOR 16f84a ; Defining processor
#include "p16f84a.inc" ; Microchip INC database
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
; frequency 4MHZ
org 0x00
goto first
first bsf 03,5
bsf 81,7; ;81 option reg.
clrf 85 ; 85 and 86 are trisa, trisb
clrf 86 ; 03 is status
bcf 03,5
movlw .255
movwf 0f
clrf 05 ; 05 port a and 06 port b
clrf 06
delay bsf 03,0
movlw d'255'
movwf 0c
movwf 0e
movwf 0d
decfsz 0c,f
goto $-1
bsf 03,0
decfsz 0d,f
goto $-1
bsf 03,0
decfsz 0e,f
goto $-1
bsf 03,0
decfsz 0f,f
goto delay
bsf 06,0
goto $
end
goto $
PROCESSOR 16f84a ; Defining processor
#include "p16f84a.inc" ; Microchip INC database
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
; frequency 4MHZ
CBLOCK 0X0C
COUNT,D1,D2,D3,D4
ENDC
org 0x00
goto first
first
clrf PORTA
clrf PORTB
bsf STATUS,RP0
bsf OPTION_REG,7; ;81 option reg.
clrf TRISA ; 85 and 86 are trisa, trisb
clrf TRISB ; 03 is status
bcf STATUS,RP0
movlw .255
movwf COUNT
delay
bsf STATUS,0
movlw .255
movwf D1
movwf D3
movwf D2
decfsz D1,f
goto $-1
bsf STATUS,0
decfsz D2,f
goto $-1
bsf STATUS,0
decfsz D3,f
goto $-1
bsf STATUS,0
decfsz D4,f
goto delay
bsf PORTB,0
goto $
end
OK, THANK YOU .Hi,
The 18 hour delay is perfect, but what would likely make the circuit inaccurate, would be crystal frequency, deviation over time and temperature and more importantly how much time you are losing by calling the delay and doing other stuff.
Hope this helps.
Tahmid
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?