Let's answer to questions...
question 1:
I am not sure if this is the correct way of calling these subroutines from (myfile.bas)... please let me know if there is a better way of performing the above operation of calling a subroutines from another file.
as your subroutine must know where to return back you must use GOSUB, RETURN statements
question2:
Another question which I think is a no brainer for most but for me i it is very hard to visualize when performing this task is ... if i compile this piece of code, will the compiler add myfile.bas and main.bas into the program memory of the PIC microcontroller or will it only include the main.bas ? lets say that I am using the 16C73B which has only 4K of space .... and myfile.bas takes up 3K while main.bas takes up 2K. does this mean that I will get an error when compiling the code.
Since some statement may be use in both program, the compiler will not add them as 3K+2K. Since my english is really not perfect, i'll try to explain it simple. try this. If you compile this line
lcdout $fe,1,"a"
it will gives you about 117 words. but if you double it
lcdout $fe,1,"a"
lcdout $fe,1,"a"
you will get about 126 words. not 2*117. So since all your INCLUDED program + main will be consider as 1, compiler will calculate regarding all repeated called statement + others. I know it's not really clear but... this is the best way i can explain.
Well done Ross! Have a beer!
In fact INCLUDE must be insert at the end of the main program to avoid to be run before main program occure. It depend on the way you work on program, you can also use 'jump' at the begining. I'll give me my version. Use it if you want.
These lines work. i use PIC12F675 for this example.
Code:
;=======
;main.bas
;=======
CMCON = 7
ANSEL = 0
TRISIO = 0
a var byte
led1 var gpio.0
led2 var gpio.1
led3 var gpio.2
gpio=0
Start:
high led1
pause 1000
high led2
pause 1000
high led3
pause 1000
gpio=0
pause 1000
gosub sub1
gosub sub2
gosub sub3
gosub sub4
GOTO Start
include "2.bas"
include "3.bas"
;====
;2.bas
;====
sub1:
for a=1 to 10
gpio=5
pause 200
gpio=0
pause 200
next
return
sub2:
for a=0 to 7
gpio=a
pause 200
next
return
;====
;3.bas
;====
sub3:
for a = 0 to 10
gpio=3
pause 200
gpio=0
pause 200
next
return
sub4:
for a=0 to 10
gpio=4
pause 200
gpio=0
pause 200
next
return
I think this method is a little bit killer... i never do this kind of task. As many, i like to see everything, every code line in my face. Since MicroCode Studio give you flexibility to jump to different Subroutine (better as shi... MPLAB that i hate so much... but it's my own opinion) it's better for you to do some copy/paste to have everything in the same windows. But i hope i answer your question !
regards
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks