Vagy létezik ennek egyszerűbb módja is?
Kód: Egész kijelölése
'Simple MASTER sample
'RS 485
'$regfile = "m162def.dat" ' specify the used micro
$regfile = "m644def.dat" ' specify the used micro
$crystal = 14745600
$baud = 9600 ' use baud rate
$hwstack = 42 ' default use 32 for the hardware stack
$swstack = 40 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
Rs485dir Alias Portd.5
Config Rs485dir = Output
Const Rs485read = 0
Const Rs485write = 1
Rs485dir = Rs485read ' go to receive mode
' TX RX
' COM0 PD.1 PD.0 rs485
' PD.5 data direction rs485
'some variables we will use
Dim S As String * 10
Dim Mybaud As Long
'when you pass the baud rate with a variable, make sure you dimesion it as a LONG
Mybaud = 9600
Dim B As Byte
Dim W As Word
Dim L As Long
B = &HFF
W = &H4567 ' set some values
L = &H12345678
S = "1234567890"
'Read "RS-485 master"
Do
'first get some data
Rs485dir = Rs485read ' go to receive mode
Waitms 10
If Ischarwaiting(#0) <> 0 Then ' (#0) did we got something back?
Serin S , 0 , D , 0 , Mybaud , 0 , 8 , 2
Serin B , 0 , D , 0 , Mybaud , 0 , 8 , 2
End If
'(
'Print "RS-485 master"
'now send it
Rs485dir = Rs485write ' go to Write mode
Waitms 10
Serout S , 0 , D , 1 , Mybaud , 0 , 8 , 2
')
' ^- 2 stop bit
' ^----- 8 data bits
' ^--------- even parity (0=N, 1 = E, 2=O)
' ^---------------- baud rate
' ^---------------------- pin number
' ^-------------------------- port so PORTD.0 and PORTD.1 are used
' ^------------------------------ for strings pass 0
' ^---------------------------------- variable
Wait 1
Loop
End