Contoh Master Modbus dengan Bascom AVR
berikut ini contoh master modbus RTU dengan menggunakan bascom avr
compiler bascom avr menyediakan fungsi library untuk master modbus yaitu “modbus.lbx” dan fungsi untuk mengirim query modbus :
MAKEMODBUS(alamat slave, fucntion code, alamat register, varbts )
function code yg tersedia
- 03 : read register
contoh
Slave Address 11
Function code 03
alamat awal reg MSB 00
alamat awal reg LSB 6B
jumlah reg MSB 00
jumlah reg LSB 03
CRC
- 06 : write single register
- 16 : write multiple register
$regfile = “m162def.dat”
$crystal = 8000000
$baud = 19200
$hwstack = 42
$swstack = 40
$framesize = 40
$lib “modbus.lbx”
Config Print1 = Portb.1 , Mode = Set
Rs485dir Alias Portb.1
Config Rs485dir = Output
Rs485dir = 0
Portc.0 = 1
‘The circuit from the help is used. See Using MAX485
‘ PB.1 data direction rs485
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Com2 = 9600 , Synchrone = 0 , Parity = Even , Stopbits = 1 , Databits = 8 , Clockpol = 0
Open “COM2:” For Binary As #1
Dim B As Byte
Dim W As Word
Dim L As Long
W = &H4567
L = &H12345678
Print “RS-485 MODBUS master”
Do
If Pinc.0 = 0 Then
Waitms 500
Print “send request to slave/server”
‘ Send one of the following three messages
‘ Print #1 , Makemodbus(2 , 3 , 8 , 2);
‘ Print #1 , Makemodbus(2 , 6 , 8 , W);
Print #1 , Makemodbus(2 , 16 , 8 , L);
End If
If Ischarwaiting(#1) <> 0 Then
B = Waitkey(#1)
Print Hex(b) ; “,”;
End If
Loop
End
sumber
http://avrhelp.mcselec.com/index.html?modbus_slaveserver.htm
Posted on 17/11/2013, in Contoh-contoh Aplikasi. Bookmark the permalink. 3 Comments.
Mas apakah ada contoh bentuk program untuk slave modbusnya? kebetulan saya sedang ada project untuk modbus dengan mikon. terimakasih
Langsung menuju link referensinya dulu gan, iam support this blog, :D