I thank everyone who helped especially people from MCS to support any kind of support.
After a lot of experimentation I succeeded to Registrar I read my transmitter and to write the adjustment to it via Modbus communication.
For those who have a similar problem with my views may be helpful.
goodbye.
[code:1:41b342a02f]
'MODBUS_MASTER
'------------------------------------------------------------------------------
$lib "modbus.lbx" 'modbus.lib contains the crcMB function
$regfile = "m16def.dat" ' chip used
$crystal = 8000000 ' xtal used
$hwstack = 64
$swstack = 64
$framesize = 64
$baud = 19200 ' baudrate N,8,1
'****************************************************************
' MCU hardware configuration
'konfiguracija ulaznih pinova
Config Pinb.0 = Input 'Taster provera LCD prvi sa leva na ploci
Config Pind.4 = Input 'Taster provera tona drugi na ploci
Config Pind.5 = Input 'Taster provera temperature LM35 treci sa leva
Config Pind.6 = Input 'Taster cetvrti
'port pocinje portx.7 - - portx.0 ukljucuje pull up resistors
Portd = &B01110000
Portb = &B00000001
Waitms 150
Config Print = Portd.2 , Mode = Set ' specify RS-485 and direction pin
Rs485dir Alias Portd.2 'make an alias
Config Rs485dir = Output 'set direction register to output
Rs485dir = 0
Config Com1 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
'****************************************************************
'Declare LCD-a: 20*4 ili 16*1a
Config Lcd = 20 * 4
Config Lcdbus = 4
Config Lcdpin = Pin , Db7 = Portb.6 , Db6 = Portb.5 , Db5 = Portb.4 , Db4 = Portb.3 , E = Portb.2 , Rs = Portb.1
Cursor Off
Cls
Lcd "MODBUS CONECT"
Wait 2
Cls
' **************************************************************
'definisanje slave address
Dim Modbus_slave As Byte
'Definisanje variable for read registers
Dim Pomreg0 As Bit , Pomreg1 As Bit
Dim Moj_reg0 As Word , Moj_reg1 As Word , Moj_reg2 As Word , Moj_reg3 As Word
Dim Reg0_1 As Byte , Reg0_2 As Byte , Reg1_1 As Byte , Reg1_2 As Byte , Reg2_1 As Byte , Reg2_2 As Byte
Dim Reg3_1 As Byte , Reg3_2 As Byte
'dimension a buffer for the modbus data
Dim Mbuf(13) As Byte , Modc As Byte , Modt As Byte
'Definisanje variable for read registers
Dim Tx_reg0 As Word , Tx_reg1 As Word
'we use the receive interrupt to receive the data
On Urxc Urxc_isr
Enable Urxc
Enable Interrupts
Do
Incr Modbus_slave
If Modbus_slave > 16 Then 'read 15 slaves
Modbus_slave = 2
End If
If Pinb.0 = 0 And Pomreg0 = 0 Then
Set Pomreg0
Tx_reg0 = Tx_reg0 + 1
Print Makemodbus(3 , 6 , 0 , Tx_reg0); ' slave 3, function 6, address 0 , value of moj_reg0
End If
If Pinb.0 = 1 Then
Reset Pomreg0
End If
If Pind.4 = 0 And Pomreg1 = 0 Then
Set Pomreg1
Tx_reg1 = Tx_reg1 + 5
Print Makemodbus(3 , 6 , 1 , Tx_reg1); ' slave 3, function 6, address 1 , value of moj_reg1
End If
If Pind.4 = 1 Then
Reset Pomreg1
End If
Waitms 5
Print Makemodbus(modbus_slave , 3 , 0 , 8); ' slave 3, function 3, address 0 , 8 byte
Home U
Lcd "Reg.0/1 " ; Tx_reg0 ; "," ; Tx_reg1 ; " "
Lowerline
Lcd "READ SLAVE No. " ; Modbus_slave ; " "
Thirdline
Lcd "Reg.0/1 " ; Moj_reg0 ; "/" ; Moj_reg1 ; " "
Fourthline
Lcd "Reg.2/3 " ; Moj_reg2 ; "/" ; Moj_reg3 ; " "
Loop
'-------- interrupt handler for the URXC interrupt ----------------------------
Urxc_isr:
sbis usr,7 ' Wait for character
rjmp urxc_isr ' wait until we can read the byte
Modt = Udr ' get the byte
If Modc = 0 Then 'if we do not have any data yet
If Modt = Modbus_slave Then 'is this the slave adress?
Modc = Modc + 1 'increase the buffer counter
Mbuf(1) = Modt 'store address in location 1
End If
Elseif Modc = 1 Then 'we received the address already
If Modt = 3 Then 'this demo works with function 6 and 3 only
Mbuf(2) = Modt 'store the function
Modc = Modc + 1 'increase buffer counter
Elseif Modt = Modbus_slave Then 'test if it is the slave number
Mbuf(1) = Modt 'store it in that case
Else
Modc = 0 'reset it
End If
Else 'we received the address and the function
Modc = Modc + 1 : Mbuf(modc) = Modt ' store the data
'If Modc = 8 Then
'Modc = 0
End If ': End If
Reg0_1 = Mbuf(4)
Reg0_2 = Mbuf(5)
Moj_reg0 = Makeint(reg0_2 , Reg0_1 ) 'registar 0 from slave '
Reg1_1 = Mbuf(6)
Reg1_2 = Mbuf(7)
Moj_reg1 = Makeint(reg1_2 , Reg1_1 ) 'registar 1 from slave '
Reg2_1 = Mbuf(8)
Reg2_2 = Mbuf(9)
Moj_reg2 = Makeint(reg2_2 , Reg2_1 ) 'registar 2 from slave '
Reg3_1 = Mbuf(10)
Reg3_2 = Mbuf(11)
Moj_reg3 = Makeint(reg3_2 , Reg3_1 ) 'registar 3 from slave '
Return
[/code:1:41b342a02f]
↧