Need help in Assembly language

Thread Starter

mpcotuong

Joined Aug 26, 2010
170
Hi All,

I am very new for assemly language. How you write delay function for 10 second? or 15 second? Please help.

Thanks, for your help

Kevin
 

lihle

Joined Apr 12, 2009
83
Hi All,

I am very new for assemly language. How you write delay function for 10 second? or 15 second? Please help.

Thanks, for your help

Kevin
man you need to tell us what crystal oscillator you are using then i can give you those delays.

lihle
'trying to read books is worth much'
 

lihle

Joined Apr 12, 2009
83
Hi All,

I am very new for assemly language. How you write delay function for 10 second? or 15 second? Please help.

Thanks, for your help

Kevin
to speed up things if you are using a 4 MHz crystal oscillator here is the code.
; Delay = 10 seconds
; Clock frequency = 4 MHz

; Actual delay = 10 seconds = 10000000 cycles
; Error = 0 %

cblock
d1
d2
d3
endc

delay10sec ;9999995 cycles
movlw 0x5A
movwf d1
movlw 0xCD
movwf d2
movlw 0x16
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0

;5 cycles
goto $+1
goto $+1
nop
return

hope this code will help you.

lihle
 

t06afre

Joined May 11, 2009
5,934
This is just a friendly tip:). But your code is very hard to read. If you use MPLAB you can include prepared header files for your chip. It will be more easy for your self and other to read your code. This is an example. You will find header files in the folder
\<program install folder>\Microchip\MPASM Suite
And by the way. No skimping on the comments:p
Rich (BB code):
#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_ON & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
cblock 0x20
Delay1 ; Define two file registers for the
Delay2 ; delay loop
endc
 
org 0
Start:
bsf STATUS,RP0 ; select Register Page 1
movlw 0
tris PORTC ;test instr
;bcf TRISC,0 ; make IO Pin B.0 an output
bcf STATUS,RP0 ; back to Register Page 0
MainLoop:
bsf PORTC,0 ; turn on LED C0
OndelayLoop:
decfsz Delay1,f ; Waste time. 
goto OndelayLoop ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
decfsz Delay2,f ; The outer loop takes and additional 3 instructions per lap * 256 loops
goto OndelayLoop ; (768+3) * 256 = 197376 instructions / 1M instructions per sec sec.
; call it a two-tenths of a second.
 
bcf PORTC,0 ; Turn off LED C0
OffDelayLoop:
decfsz Delay1,f ; same delay as above
goto OffDelayLoop
decfsz Delay2,f
goto OffDelayLoop
goto MainLoop ; Do it again...
end
 
Top