Hello i would like to ask someone to help me understand how to put a subroutine or subfunction in a module and being able to call it from the main program. Also i would like to declare the variables that ill use in the module as Global Variables.
I tried using this code from XOR (POST#2) http://www.mikroe.com/forum/viewtopic.p ... all#p29064.
But it didn't work.
Any help would be nice.
Regards, Kostas.
Modules Subprocedure Subfunction
Re: Modules Subprocedure Subfunction
xor's post dates before mB PRO was introduced, so there's no mention of routines' prototypes that need to be added for visibility from outside of the module. You should have a look at 'Program Organisation' chapter in Help but for a quick reference here's slightly modified xor's module example
Code: Select all
module My_New_Module
dim modvar1, modvar2 as byte ' variables visible to code that included the module
sub procedure PORTB_LED ' prototype making procedure visible to code that included the module
Implements
dim modvar3 as byte ' variable local to module
sub procedure delay_1second ' local procedure
delay_ms(1000)
end sub
sub procedure PORTB_LED
modvar1 = $FF
modvar2 = 0
modvar3 = %10101010
PORTB = modvar1
delay_1second
PORTB = modvar2
delay_1second
PORTB = modvar3
end sub
end.
-
- Posts: 15
- Joined: 23 Nov 2012 23:17
Re: Modules Subprocedure Subfunction
Thank you for helping me and for the reply !
Best Regards, Kostas.
Best Regards, Kostas.