سلام به همه eca ها :biggrin:
این برانامه رباتمه(مسیریاب):
[code=qbasic]
$regfile = "m32def.dat"
$crystal = 8000000
'_________________________ CONFIG TIMER MOD=PWM ________________________________
Config Timer1 = Pwm , Pwm = 8 , Prescale = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down
Start Timer1
'______________________________ CONFIG PORT ____________________________________
Config Portd = Output
Config Portb = Input
Config Portc = Input
'__________________________ DECLARE & SUB ______________________________________
Declare Sub Left210()
Declare Sub Left200()
Declare Sub Left180()
Declare Sub Left130()
Declare Sub Back()
Declare Sub Forward()
Declare Sub Right210()
Declare Sub Right200()
Declare Sub Right180()
Declare Sub Right130()
'____________________________ VARIYBALE ________________________________________
Dim S(16) As Byte
Dim Ss As String * 16
Dim I As Byte
'__________________________ START PROGRAM ______________________________________
'____________________________ SUB Black ________________________________________
Do
S(1) = Pinb.0
S(2) = Pinb.1
S(3) = Pinb.2
S(4) = Pinb.3
S(5) = Pinb.4
S(6) = Pinb.5
S(7) = Pinb.6
S(8) = Pinb.7
S(9) = Pinc.7
S(10) = Pinc.6
S(11) = Pinc.5
S(12) = Pinc.4
S(13) = Pinc.3
S(14) = Pinc.2
S(15) = Pinc.1
S(16) = Pinc.0
Ss = Str(s(1)) + Str(s(2)) + Str(s(3)) + Str(s(4)) + Str(s(5)) + Str(s(6)) + Str(s(7)) + Str(s(8)) + Str(s(9)) + Str(s(10)) + Str(s(11)) + Str(s(12)) + Str(s(13)) + Str(s(14)) + Str(s(15)) + Str(s(16))
If Ss = "0111111111111111" Then Call Right210()
If Ss = "1011111111111111" Then Call Right200()
If Ss = "1101111111111111" Then Call Right180()
If Ss = "1110111111111111" Then Call Right130()
If Ss = "1111011111111111" Then Call Right130()
If Ss = "1111101111111111" Then Call Right130()
If Ss = "1111110111111111" Then Call Right130()
If Ss = "1111111011111111" Then Call Forward()
If Ss = "1111111101111111" Then Call Forward()
If Ss = "1111111110111111" Then Call Left130()
If Ss = "1111111111011111" Then Call Left130()
If Ss = "1111111111101111" Then Call Left130()
If Ss = "1111111111110111" Then Call Left130()
If Ss = "1111111111111011" Then Call Left180()
If Ss = "1111111111111101" Then Call Left200()
If Ss = "1111111111111110" Then Call Left210()
If Ss = "0011111111111111" Then Call Right210()
If Ss = "1001111111111111" Then Call Right200()
If Ss = "1100111111111111" Then Call Right180()
If Ss = "1110011111111111" Then Call Right130()
If Ss = "1111001111111111" Then Call Right130()
If Ss = "1111100111111111" Then Call Right130()
If Ss = "1111110011111111" Then Call Forward()
If Ss = "1111111001111111" Then Call Forward()
If Ss = "1111111100111111" Then Call Forward()
If Ss = "1111111110011111" Then Call Left130()
If Ss = "1111111111001111" Then Call Left130()
If Ss = "1111111111100111" Then Call Left130()
If Ss = "1111111111110011" Then Call Left180()
If Ss = "1111111111111001" Then Call Left200()
If Ss = "1111111111111100" Then Call Left210()
If Ss = "0001111111111111" Then Call Right210()
If Ss = "1000111111111111" Then Call Right200()
If Ss = "1100011111111111" Then Call Right180()
If Ss = "1110001111111111" Then Call Right130()
If Ss = "1111000111111111" Then Call Right130()
If Ss = "1111100011111111" Then Call Right130()
If Ss = "1111110001111111" Then Call Forward()
If Ss = "1111111000111111" Then Call Forward()
If Ss = "1111111100011111" Then Call Left130()
If Ss = "1111111110001111" Then Call Left130()
If Ss = "1111111111000111" Then Call Left130()
If Ss = "1111111111100011" Then Call Left180()
If Ss = "1111111111110001" Then Call Left200()
If Ss = "1111111111111000" Then Call Left210()
If Ss = "0000111111111111" Then Call Right210()
If Ss = "1000011111111111" Then Call Right200()
If Ss = "1100001111111111" Then Call Right130()
If Ss = "1110000111111111" Then Call Right130()
If Ss = "1111000011111111" Then Call Right130()
If Ss = "1111100001111111" Then Call Right130()
If Ss = "1111110000111111" Then Call Forward()
If Ss = "1111111000011111" Then Call Left130()
If Ss = "1111111100001111" Then Call Left130()
If Ss = "1111111110000111" Then Call Left130()
If Ss = "1111111111000011" Then Call Left130()
If Ss = "1111111111100001" Then Call Left200()
If Ss = "1111111111110000" Then Call Left210()
If Ss = "0000011111111111" Then Call Right210()
If Ss = "1000001111111111" Then Call Right200()
If Ss = "1100000111111111" Then Call Right180()
If Ss = "1110000011111111" Then Call Right130()
If Ss = "1111000001111111" Then Call Right130()
If Ss = "1111100000111111" Then Call Forward()
If Ss = "1111110000011111" Then Call Forward()
If Ss = "1111111000001111" Then Call Left130()
If Ss = "1111111100000111" Then Call Left130()
If Ss = "1111111110000011" Then Call Left180()
If Ss = "1111111111000001" Then Call Left200()
If Ss = "1111111111100000" Then Call Left210()
'(
'![32](https://www.eca.ir/forums/core/images/smilies/32.png)
Loop
'________________________ SUB FORWARD __________________________________________
Sub Forward()
Reset Portd.0
Set Portd.1
Pwm1b = 210
Set Portd.2
Reset Portd.3
Pwm1a = 210
Return
End Sub
'___________________________SUB RIGHT ___________________________________________
Sub Right210()
Set Portd.2
Reset Portd.3
Pwm1a = 210
Set Portd.0
Reset Portd.1
Pwm1b = 210
Return
End Sub
Sub Right200()
Set Portd.2
Reset Portd.3
Pwm1a = 210
Set Portd.0
Reset Portd.1
Pwm1b = 210
Return
End Sub
Sub Right180()
Set Portd.2
Reset Portd.3
Pwm1a = 210
Set Portd.0
Reset Portd.1
Pwm1b = 210
Return
End Sub
Sub Right130()
Reset Portd.0
Set Portd.1
Pwm1b = 175
Set Portd.2
Reset Portd.3
Pwm1a = 200
Return
End Sub
''''''''&# 039;''''''' 9;'''''''' ''''''''&# 039;''''''' 9;'''''''' ''''''''&# 039;''''''' 9;'''''''' '''''
Sub Left210()
Reset Portd.0
Set Portd.1
Pwm1b = 210
Reset Portd.2
Set Portd.3
Pwm1a = 210
Return
End Sub
Sub Left200()
Reset Portd.0
Set Portd.1
Pwm1b = 210
Reset Portd.2
Set Portd.3
Pwm1a = 210
Return
End Sub
Sub Left180()
Reset Portd.0
Set Portd.1
Pwm1b = 210
Reset Portd.2
Set Portd.3
Pwm1a = 210
Return
End Sub
Sub Left130()
Reset Portd.0
Set Portd.1
Pwm1b = 205
Set Portd.2
Reset Portd.3
Pwm1a = 170
Return
End Sub
[/code]
از چه دستوری استفاده کنم تا اگه خطو گم کرد آخرین وضعیت سنسور هارو بدونه و به طرف مورد نظر بچرخه؟؟؟
این برانامه رباتمه(مسیریاب):
[code=qbasic]
$regfile = "m32def.dat"
$crystal = 8000000
'_________________________ CONFIG TIMER MOD=PWM ________________________________
Config Timer1 = Pwm , Pwm = 8 , Prescale = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down
Start Timer1
'______________________________ CONFIG PORT ____________________________________
Config Portd = Output
Config Portb = Input
Config Portc = Input
'__________________________ DECLARE & SUB ______________________________________
Declare Sub Left210()
Declare Sub Left200()
Declare Sub Left180()
Declare Sub Left130()
Declare Sub Back()
Declare Sub Forward()
Declare Sub Right210()
Declare Sub Right200()
Declare Sub Right180()
Declare Sub Right130()
'____________________________ VARIYBALE ________________________________________
Dim S(16) As Byte
Dim Ss As String * 16
Dim I As Byte
'__________________________ START PROGRAM ______________________________________
'____________________________ SUB Black ________________________________________
Do
S(1) = Pinb.0
S(2) = Pinb.1
S(3) = Pinb.2
S(4) = Pinb.3
S(5) = Pinb.4
S(6) = Pinb.5
S(7) = Pinb.6
S(8) = Pinb.7
S(9) = Pinc.7
S(10) = Pinc.6
S(11) = Pinc.5
S(12) = Pinc.4
S(13) = Pinc.3
S(14) = Pinc.2
S(15) = Pinc.1
S(16) = Pinc.0
Ss = Str(s(1)) + Str(s(2)) + Str(s(3)) + Str(s(4)) + Str(s(5)) + Str(s(6)) + Str(s(7)) + Str(s(8)) + Str(s(9)) + Str(s(10)) + Str(s(11)) + Str(s(12)) + Str(s(13)) + Str(s(14)) + Str(s(15)) + Str(s(16))
If Ss = "0111111111111111" Then Call Right210()
If Ss = "1011111111111111" Then Call Right200()
If Ss = "1101111111111111" Then Call Right180()
If Ss = "1110111111111111" Then Call Right130()
If Ss = "1111011111111111" Then Call Right130()
If Ss = "1111101111111111" Then Call Right130()
If Ss = "1111110111111111" Then Call Right130()
If Ss = "1111111011111111" Then Call Forward()
If Ss = "1111111101111111" Then Call Forward()
If Ss = "1111111110111111" Then Call Left130()
If Ss = "1111111111011111" Then Call Left130()
If Ss = "1111111111101111" Then Call Left130()
If Ss = "1111111111110111" Then Call Left130()
If Ss = "1111111111111011" Then Call Left180()
If Ss = "1111111111111101" Then Call Left200()
If Ss = "1111111111111110" Then Call Left210()
If Ss = "0011111111111111" Then Call Right210()
If Ss = "1001111111111111" Then Call Right200()
If Ss = "1100111111111111" Then Call Right180()
If Ss = "1110011111111111" Then Call Right130()
If Ss = "1111001111111111" Then Call Right130()
If Ss = "1111100111111111" Then Call Right130()
If Ss = "1111110011111111" Then Call Forward()
If Ss = "1111111001111111" Then Call Forward()
If Ss = "1111111100111111" Then Call Forward()
If Ss = "1111111110011111" Then Call Left130()
If Ss = "1111111111001111" Then Call Left130()
If Ss = "1111111111100111" Then Call Left130()
If Ss = "1111111111110011" Then Call Left180()
If Ss = "1111111111111001" Then Call Left200()
If Ss = "1111111111111100" Then Call Left210()
If Ss = "0001111111111111" Then Call Right210()
If Ss = "1000111111111111" Then Call Right200()
If Ss = "1100011111111111" Then Call Right180()
If Ss = "1110001111111111" Then Call Right130()
If Ss = "1111000111111111" Then Call Right130()
If Ss = "1111100011111111" Then Call Right130()
If Ss = "1111110001111111" Then Call Forward()
If Ss = "1111111000111111" Then Call Forward()
If Ss = "1111111100011111" Then Call Left130()
If Ss = "1111111110001111" Then Call Left130()
If Ss = "1111111111000111" Then Call Left130()
If Ss = "1111111111100011" Then Call Left180()
If Ss = "1111111111110001" Then Call Left200()
If Ss = "1111111111111000" Then Call Left210()
If Ss = "0000111111111111" Then Call Right210()
If Ss = "1000011111111111" Then Call Right200()
If Ss = "1100001111111111" Then Call Right130()
If Ss = "1110000111111111" Then Call Right130()
If Ss = "1111000011111111" Then Call Right130()
If Ss = "1111100001111111" Then Call Right130()
If Ss = "1111110000111111" Then Call Forward()
If Ss = "1111111000011111" Then Call Left130()
If Ss = "1111111100001111" Then Call Left130()
If Ss = "1111111110000111" Then Call Left130()
If Ss = "1111111111000011" Then Call Left130()
If Ss = "1111111111100001" Then Call Left200()
If Ss = "1111111111110000" Then Call Left210()
If Ss = "0000011111111111" Then Call Right210()
If Ss = "1000001111111111" Then Call Right200()
If Ss = "1100000111111111" Then Call Right180()
If Ss = "1110000011111111" Then Call Right130()
If Ss = "1111000001111111" Then Call Right130()
If Ss = "1111100000111111" Then Call Forward()
If Ss = "1111110000011111" Then Call Forward()
If Ss = "1111111000001111" Then Call Left130()
If Ss = "1111111100000111" Then Call Left130()
If Ss = "1111111110000011" Then Call Left180()
If Ss = "1111111111000001" Then Call Left200()
If Ss = "1111111111100000" Then Call Left210()
'(
'
![32](https://www.eca.ir/forums/core/images/smilies/32.png)
Loop
'________________________ SUB FORWARD __________________________________________
Sub Forward()
Reset Portd.0
Set Portd.1
Pwm1b = 210
Set Portd.2
Reset Portd.3
Pwm1a = 210
Return
End Sub
'___________________________SUB RIGHT ___________________________________________
Sub Right210()
Set Portd.2
Reset Portd.3
Pwm1a = 210
Set Portd.0
Reset Portd.1
Pwm1b = 210
Return
End Sub
Sub Right200()
Set Portd.2
Reset Portd.3
Pwm1a = 210
Set Portd.0
Reset Portd.1
Pwm1b = 210
Return
End Sub
Sub Right180()
Set Portd.2
Reset Portd.3
Pwm1a = 210
Set Portd.0
Reset Portd.1
Pwm1b = 210
Return
End Sub
Sub Right130()
Reset Portd.0
Set Portd.1
Pwm1b = 175
Set Portd.2
Reset Portd.3
Pwm1a = 200
Return
End Sub
''''''''&# 039;''''''' 9;'''''''' ''''''''&# 039;''''''' 9;'''''''' ''''''''&# 039;''''''' 9;'''''''' '''''
Sub Left210()
Reset Portd.0
Set Portd.1
Pwm1b = 210
Reset Portd.2
Set Portd.3
Pwm1a = 210
Return
End Sub
Sub Left200()
Reset Portd.0
Set Portd.1
Pwm1b = 210
Reset Portd.2
Set Portd.3
Pwm1a = 210
Return
End Sub
Sub Left180()
Reset Portd.0
Set Portd.1
Pwm1b = 210
Reset Portd.2
Set Portd.3
Pwm1a = 210
Return
End Sub
Sub Left130()
Reset Portd.0
Set Portd.1
Pwm1b = 205
Set Portd.2
Reset Portd.3
Pwm1a = 170
Return
End Sub
[/code]
از چه دستوری استفاده کنم تا اگه خطو گم کرد آخرین وضعیت سنسور هارو بدونه و به طرف مورد نظر بچرخه؟؟؟
دیدگاه