:exclamation: دیگه قاط زدم!!! هر کاری می کنم ج نمی ده... در بهترین حات فقط همون لحظه اول دیتا دریافت میشه بعد دیگه هیچ دیتایی نمیاد... یعنی با تغییر دیتا تو ورودی خروجی هیچ تغیری نمیکنه...
کد:
[align=left]
فرستنده
$regfile = "m8def.dat"
$crystal = 8000000
$baud = 9600
'$sim
'---------------------------------------------
Config Portc = Input
Config Portb = Output
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 _
, Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
Config Lcd = 16 * 2
Cursor Off
Dim Cr As String * 1
Dim Cl As String * 1
Dim Cpw As String * 1
Dim C4 As String * 1
Dim Y As String * 3
Dim A As Byte , B As Byte , C As Byte , D As Word , E As Byte
Dim R As Byte
Dim L As Byte
Dim P As Byte
'---------------------------------------------
Set Portb.1
Reset Portb.2
'---------------------------------------------
Main:
Do
R = Pinc And &B00000011
L = Pinc And &B00001100
P = Pinc And &B00110000
Shift L , Right , 2
Shift P , Right , 4
If R = 1 Then Cr = "U"
If R = 2 Then Cr = "D"
If R = 3 Or R = 0 Then Cr = "X"
If L = 1 Then Cl = "U"
If L = 2 Then Cl = "D"
If L = 3 Or L = 0 Then Cl = "X"
If P = 1 Then Cpw = "U"
If P = 2 Then Cpw = "D"
If P = 3 Or P = 0 Then Cpw = "X"
For A = 0 To 3
Print "H" ; Cr ; Cl ; Cpw ; "E" ; Chr(13)
Waitms 20
Next A
Loop
End
گیرنده
$regfile = "m8def.dat"
$crystal = 8000000
$baud = 9600
'Const Cmaxchar = 20
'$sim
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 _
, Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
Config Lcd = 16 * 2
Cursor Off
'Config Servos = 2 , Servo1 = Portb.6 , Servo2 = Portb.7 , Reload = 20
'Config Timer1 = Pwm , Prescale = 8 , Pwm = 10 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down
On Urxc Rec_isr 'define serial receive ISR
Enable Urxc 'enable receive isr
Enable Interrupts
'Enable Timer1
'Start Timer1
'---------------------------------------------
Config Pind.7 = Output , Pind.6 = Output , Pind.5 = Output
Config Portb = Output
Dim S As String * 5
Dim Sr As String * 1
Dim Sl As String * 1
Dim Spw As String * 1
Dim A As Byte , B As Bit , D As Byte , P As Word , X As Word , Y As Word
S = " "
P = 23
'---------------------------------------------
Main:
Home : Lcd "Elahe" : Wait 3 : Cls
Do
If B = 1 Then 'we received something
Disable Serial
Incr Y : Locate 2 , 11 : Lcd Y
Home : Lcd S ; " "
'Locate 2 , 6 : Lcd Left(s , 1) ; Mid(s , 4 , 1) ; Mid(s , 3 , 1) ; Mid(s , 2 , 1) ; Right(s , 1)
If Right(s , 1) = "H" Then
Sr = Mid(s , 2 , 1)
Sl = Mid(s , 3 , 1)
Spw = Mid(s , 4 , 1)
If Sr = "X" Then : Reset Portb.5 : Reset Portb.0 : End If
If Sr = "D" Then : Reset Portb.5 : Set Portb.0 : End If
If Sr = "U" Then : Set Portb.5 : Reset Portb.0 : End If
If Sl = "X" Then : Reset Portb.3 : Reset Portb.4 : End If
If Sl = "D" Then : Reset Portb.3 : Set Portb.4 : End If
If Sl = "U" Then : Set Portb.3 : Reset Portb.4 : End If
If Spw = "D" Then : P = P + 200 : If P > 1023 Then P = 1023 : End If
If Spw = "U" Then : P = P - 200 : If P < 23 Then P = 23 : End If
Pwm1a = P : Pwm1b = P
End If
Home L : Lcd P ; " "
Reset B 'reset receive flag
Enable Serial
End If
Loop
End
Rec_isr: 'read UDR only once
D = Udr
If Chr(d) = "P" Or Chr(d) = "H" Then
Smhha:
S = S + Chr(d)
A = Len(s)
Incr X : Locate 1 , 9 : Lcd X
If A < 5 Then : D = Udr : Goto Smhha : End If
Set B
End If 'set flag
Return
[/align]