۰۷-شهریور-۱۳۸۸, ۲۳:۱۵:۴۴
ميخواستم در زيربرنامه و تابع و نحوه ي بكاربردن متغيرها در ان به طور كاملا جز به جز توضيح دهيد(بسكام)از روي جزوه اينجا و كتاب خوندم ولي متوجه نشدم .لطفا چنتا مثال هم بزنيد
"regfile = "m16def.dat$
crystal = 12000000$
Config Porta = Output
: Q
Set Porta.0
WAitms 600
Reset Porta.0
Waitms 600
Goto q
End
"regfile = "m16def.dat$
crystal = 12000000$
Config Porta = Output
: Q
Set Porta.0
WAitms 600
Reset Porta.0
Waitms 600
Goto Q
End
$regfile = "m16def.dat"
$crystal = 12000000
Config Porta = Output
E
Do
Gosub Q
Set Porta.0
WAitms 600
Loop
End
Q:
Reset Porta.0
Waitms 600
Return
ON var [GOTO] [GOSUB] label1 [, label2 ] [,CHECK]
$regfile = "m16def.dat"
$crystal = 12000000
Config Porta = Output
Dim S As Byte
Do
On S Gosub Q , W , E , R , T , Y , U , I
Incr S
Wait 1
Loop
End
Q:
Set Porta.0
Return
W:
Set Porta.1
Return
E:
Set Porta.2
Return
R:
Set Porta.3
Return
T:
Set Porta.4
Return
Y:
Set Porta.5
Return
U:
Set Porta.6
Return
I
Set Porta.7
Return
[/quote]
مثال با دستور goto:
[quote]
$regfile = "m16def.dat"
$crystal = 12000000
Config Porta = Output
Dim S As Byte
A:
Wait 1
On S Goto Q , W
End
Q:
Set Porta.0
Incr S
Goto A
W:
Set Porta.1
Goto A
DECLARE FUNCTION TEST[( [BYREF/BYVAL]var as type1)] As type2
"regfile = "m16def.dat$
crystal = 12000000$
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portd.0 , Db5 = Portd.1 , Db6 = Portd.2 , Db7 = Portd.3 , E = Portd.4 , Rs = Portd.5
Declare Function Myfunction (Byval I As Integer , S As String )As Integer
Dim K As Integer , Z As String*10, T As Integer
K = 5 : Z = "123 " : T = Myfunction(k , Z)
LocAte 1 , 1
Lcd T '25
Locate 1 , 7
Lcd Z 'Bascom
Locate 2 , 1
Lcd K '5
End
Function Myfunction (Byval I As Integer , S As String )As Integer
local P As Integer
Functions:
P = I * 5
I = 5
S = "Bascom”
T = P
Myfunction = T
End Function
DECLARE SUB TEST[( [BYREF/BYVAL] var as type)]
SUB Name [ ( var1) ]
"regfile = "m16def.dat$
crystal = 12000000$
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portd.0 , Db5 = Portd.1 , Db6 = Portd.2 , Db7 = Portd.3 , E = Portd.4 , Rs = Portd.5
Dim A As Byte , B1 As Byte , C As Byte
Declare Sub Test ( A As Byte)
A =1 : B1 = 2 : C = 3
Lcd A ; B1 ; C '123 will print
Call Test (B1)
End
Sub Test(a As Byte)
Locate 2 , 1
Lcd A ; B1 ; C '123 will print
End Sub
CALL TEST( VAR1 , VAR2,....)
TEST VAR1 , VAR2
"regfile = "m16def.dat$
crystal = 12000000$
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portd.0 , Db5 = Portd.1 , Db6 = Portd.2 , Db7 = Portd.3 , E = Portd.4 , Rs = Portd.5
Dim A As Byte , B As Byte
Declare Sub Test ( B1 As Byte , Byval B2 As Byte)
A =65
Call Test ( A , 5)
Test A , 5
Locate 1 , 1
lcd A ' will print A = 10
End
Sub Test(b1 As Byte , Byval B2 As Byte)
B1 = 10
B2 = 15
Locate 1 , 8
Lcd B1
Locate 2 , 1
Lcd B2
End Sub
LOCAL VAR As Type
"regfile = "m16def.dat$
crystal = 12000000$
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portd.0 , Db5 = Portd.1 , Db6 = Portd.2 , Db7 = Portd.3 , E = Portd.4 , Rs = Portd.5
Declare Sub Test2
Do
Call test2
Loop
End
Sub Test2
Local A As Byte
Incr A
Lcd A
End Sub