Call Them

Status
Not open for further replies.

Ayne

New Member
How can i call a program that is in another assembly file.
I mean;

Our main program file in which we are working.
Code:
main
movlw   .255 
movwf   PORTB
Call   delay
movlw   .0
movwf   PORTB
call   delay
Goto $ - 6
End.

Our another file that has libraries(like delay, serial port, etcetc).
Code:
delay
movlw   255
movwf   i     ;our variable i
DecFSZ   i, F
Goto $ - 1
return

Now how can i call a delay routine in our main working file???
 
A simple option is to put them in an include file, and add it at the top of the program - but a more complicated (and better?) option is to use the linker - personally I never have, I'd sooner cut and paste my common subroutines in.
 
Is there any subroutine of delay on any website???

_________________________________________________________________
/*Nigel Goodwin likes C complier for microcontrollers*/
/*Nigel Goodwin always use MPLABSIM simulator */
 
Ayne,

When you find the delay code generator, could you post a link to it.

I would like to have that.
 
mramos1 said:
Ayne,

When you find the delay code generator, could you post a link to it.

I would like to have that.

Jesus! - you've got almost 1500 posts here, and you can't be bothered to look on the PICList for the blindingly obvious delay code generator?.

Here's the link!
 
I thought if Ayne needs it and was off to find it, I could ask him for a link.

He does not have to post it. I do not see where it has to do with anything but I will go find it later. I can find the PIClist site and wing the delay code generator part.

I do stuff for others to help them out when they ask, if I can, and it was not like asking a lot.

Sorry.

I tought I would save time on something that I might use (sure I would try it and going full on PIC assembler and out of the BASIC) as well others might want it as well and be able to find it here from a link.

By the tone, I take it PICList should be something I check though I still use BASIC?
 
Online version:



or



EDIT: Never found the Windows version. But that works for me.
 
Last edited:
Code:
Delay X cycles (7-1030) exclusive (11 to 1034 cycles inclusive of call and return) 
From Dwayne Reid 

;10 bit delay routine providing 1 cycle resolution.  Works with both 12 & 14 bit core PICs.
;Original idea from Mike Harrison.  This version by Dwayne Reid
;
;enters with upper 8 bits of delay in DELAYU, lower 2 bits in bits 1,0 of DELAYL
;bits 7..2 in DELAYL can be used as flags for whatever purpose desired.
;returns with W destroyed
Delay10bit      ;delay is 10 bit value + 7 cycles ( + call + return, if any)
     incf        DELAYU,F        ;correct for dec & test instead of test & dec
Dly10bLoop
     comf        DELAYL,W        ;invert LSBs
     decfsz      DELAYU,F
       goto      Dly10bLoop      ;coarse delay to closest 4 cycles
     andlw       b'00000011'
     addwf       PCL,F
     nop
     nop
     nop

I want to gernate variable delays in my program
I found this on the PICLIST.

Code:
;bits 7..2 in DELAYL can be used as flags for whatever purpose desired.
What is the meaning of above line??? For what pupose i can use...Can any one gave me example???
 
Why not use the delay code generator there?, two of us have now posted direct links to it.
cuz i need different delays in my program.
Just like this
movlw .34 ;delay of 34uSec
call delay
above code is just for an example...

But the code generater creat a fix delay.
 
Ayne said:
cuz i need different delays in my program.
Just like this

above code is just for an example...

But the code generater creat a fix delay.

What sort of range and resolution do you need?, my tutorials generally include variable delays - using a 1mS resolution (based on the code generator).
 
Ayne.

You can pick the range of delays times you need, say 1ms to 500ms (1/2 a second). I would make a 1ms delay via the online calc/delay generator.

Then convert it to a subroutine you can CALL. Each time you call it you get about 1ms (there is some overhead).

For 25ms make a loop to call it 25 times.

MPLABS has a stopwatch you can time it with too.

If you need 500ms, you can call another routine that you call 100msec and loop 5 times calling it. And of course 100msec: calls your 1ms subroutine 100 times.

Hope that makes since.
 
Thanks mramos1.
Is there any 16-16 bit multiplication program offline......
16-16 bit multiplication is available on piclist but i can use only it online.
I want to download 16-16 bit multiplication(for windows) program to use it later ...
 
There are plenty of multiplication examples about - and the PICList isn't restricted in any way, simply cut and paste the code off the screen?.

If you like I can post the maths routines I always use?, they are about to appear in my next tutorial (interfacing a Dallas DS1620 temperature sensor).

Quick edit, here are the routines I use!.

Code:
;16 bit Maths subroutines
Sub16:
       		COMF   Acc2H, f       		; Take two's complement
		COMF   Acc2L, f       		; of Acc2. If zero, Acc2L
		INCF   Acc2L, f
		BTFSC  STATUS, Z   		; overflowed, so carry
		INCF   Acc2H, f       		; into Acc2H.
Add16:
       		BCF    Flags, OverFlow 		; clear overflow flag
		MOVF   Acc2L, w    		; Add the LSBs. If carry,
		ADDWF  Acc1L, f
		BTFSC  STATUS, C   		; increment MSB of sum.
		INCF   Acc1H, f
		MOVF   Acc2H, w   		; Add the MSBs
		ADDWF  Acc1H, f
		BTFSC  STATUS, C   		; check for sum overflow
		BSF    Flags, OverFlow 		; set overflow flag
		MOVF   Acc1L, w    		; return lobyte in W
		RETURN
Mult16:
		CLRF   Acc3H          		; Clear product to make
		CLRF   Acc3L         		; way for new calculation.
		MOVLW  d'16'        		; Number of bits to calc.
		MOVWF  tmp1
Multiply_loop
		BCF    STATUS, C
		RLF    Acc3L, f        		; Shift product left.
		RLF    Acc3H, f
		BCF    STATUS, C
		RLF    Acc1L, f        		; Shift multiplicand left.
		RLF    Acc1H, f
		BTFSS  STATUS, C    		; If carry, add multiplier
		GOTO   Multiply_skip
		MOVF   Acc2L, w      		; to the product. Else skip.
		ADDWF  Acc3L, f
		BTFSC  STATUS, C    		; 16-bit addition: prod+mulp
		INCF   Acc3H, f
		MOVF   Acc2H, w
		ADDWF  Acc3H, f
Multiply_skip
		DECFSZ tmp1
		GOTO   Multiply_loop
		MOVF   Acc3H, w
		MOVWF  Acc1H        		; return answer in Acc1
		MOVF   Acc3L, w
		MOVWF  Acc1L        		; with lobyte in W
		RETURN

DIV16:          MOVF    Acc2H, w                ; Check for division by 0.
		IORWF   Acc2L, w
		BTFSC   STATUS, Z
		RETLW   d'255'        		; Error code= 255: return.
		MOVLW   d'1'          		; Otherwise, initialize variables
		MOVWF   tmp1
		CLRF    tmp2         		; index for the division.
		CLRF    Acc3H
		CLRF    Acc3L
Divide_sh_loop  BTFSC   Acc2H, d'7'   		; Shift divisor left
		GOTO    Divide_d1
		BCF     STATUS, C     		; until msb is in
		RLF     Acc2L, f         	; Acc2H.7.
		RLF     Acc2H, f         	; tmp1 = no. of shifts+1.
		INCF    tmp1
		GOTO    Divide_sh_loop
Divide_d1       BCF     STATUS, C
		RLF     Acc3L, f          	; Shift quotient left.
		RLF     Acc3H, f
		MOVF    Acc2L,w       		; top = top - btm.
		SUBWF   Acc1L, f
		BTFSC   STATUS, C     		; If top - btm < 0 then
		GOTO    Divide_d2
		MOVLW   d'1'          		; top = top + btm
		SUBWF   Acc1H, f
		BTFSC   STATUS, C     		; The idea is to do the
		GOTO    Divide_d2
		INCF    Acc1H, f         	; the subtraction and comparison
		MOVF    Acc2L, w      		; (top > btm?) in one step.
		ADDWF   Acc1L, f
		goto    Divide_reentr 		; Then, if btm > top, undo <Microchip instruction>
Divide_d2       MOVF    Acc2H, w      		; the subtraction by adding
		SUBWF   Acc1H, f
		BTFSS   STATUS, C     		; top and btm back together
		goto    Divide_less   		; <Microchip instruction>
		BSF     Acc3L,  d'0'
Divide_reentr
		BCF     STATUS, C
		RRF     Acc2H, f
		RRF     Acc2L, f
		DECFSZ  tmp1
		GOTO    Divide_d1
		MOVF    Acc3H, w
		MOVWF   Acc1H         		; return answer in Acc1
		MOVF    Acc3L, w
		MOVWF   Acc1L        		; with lobyte in W
		RETURN
Divide_less     MOVF    Acc2L, w      		; btm > top, so
		ADDWF   Acc1L, f
		BTFSC   STATUS, C     		; undo the subtraction by
		INCF    Acc1H, f         	; adding them back together.
		MOVF    Acc2H, w
		ADDWF   Acc1H, f
		goto    Divide_reentr 		; <Microchip instruction>

SHIFTR:         MOVWF    Acc2L
_LoopR          BCF      STATUS, C
		RRF      Acc1H, F
		RRF      Acc1L, F
		DECFSZ   Acc2L
		GOTO     _LoopR
		MOVF     Acc1L, W
		RETURN

SHIFTL:         MOVWF    Acc2L
_LoopL          BCF      STATUS, C
		RLF      Acc1L, F
		RLF      Acc1H, F
		DECFSZ   Acc2L
		GOTO     _LoopL
		MOVF     Acc1L, W
		RETURN
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…