Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

multiple source files help

Status
Not open for further replies.

krpz

New Member
i have the code below and i want to move the delay routines in a new source file "delay_routines.asm"
so i have 2 source files and from the "main.asm" to call delay subroutines in delay_routines.asm

what code directives i need to use? can someone help me?


Code:
List p=pic16f877
include "P16F877.INC"


__CONFIG _CP_OFF & _WDT_OFF &_BODEN_OFF & _PWRTE_ON & _HS_OSC & _WDT_OFF & _LVP_OFF & _CPD_OFF
ERRORLEVEL -302


;  variable declaration

cblock 0x20
;delay_counter1
;delay_counter2

main
call delay_1ms
call delay_20ms

;######################################################################
;						Delay Routines
;######################################################################
;4MHz clock frequency

delay_1ms							;delay = 0.001 seconds = 1000 cycles
		movlw 0xc6					;c6=198 to decimal
		movwf delay_counter1
		movlw 0x01              
		movwf delay_counter2
delay_1ms_0
		decfsz delay_counter1, f   	;this instruction = one cycle
		goto $+2					;this instruction = two cycles
		decfsz delay_counter2, f	
		goto delay_1ms_0				; 993 cycles
		goto $+1					; 
		nop							; 3 cycles
		return						; 4 cycles(include call)


delay_20ms						;delay = 0.02 sec = 20000 cycles
		movlw 0x9e
		movwf delay_counter1
		movlw 0x10
		movwf delay_counter2
delay_20ms_0
		decfsz delay_counter1,f
		goto $+2
		decfsz delay_counter2,f
		goto delay_20ms_0				;19993 cycles
		goto $+1					
		nop							;3 cycles
		return						;4 cycles(include call)



END
 
Last edited:
You do them in .INC files. Create a file named Delay.INC and copy/paste your delay routines into that file and save it. Don't type "end" after the routines.

Then in your main code, just above where it says "END", type -

Code:
                include               "Delay.INC"
 
i also have some Macros and i try to make the same as the delay_routines and i make a new "macro.inc" file but it doesnt work . Do you know why??
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top