Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 29, 2024, 11:03:57 11:03


Login with username, password and session length


Pages: [1]
Print
Author Topic: Try This  (Read 2928 times)
0 Members and 1 Guest are viewing this topic.
Shinta
Newbie
*
Offline Offline

Posts: 21

Thank You
-Given: 20
-Receive: 3


« on: January 12, 2008, 02:25:07 02:25 »

Try the following fragment of code.
It functions as slave or master device and the data to transfer or read is in 5 bytes However it can be more if you change de variables arrays and the for iterations.

Originally the program is slave but can be changed as master easy.
The program consist in that the slave wait the data from other device (the master) and then it respond to the master with the same data receibed

It works for me

'Transfer data procedure
Sub Procedure TransmiteDatos
    'Master address
    DatosTransmitir[0] = 1
    'Data to transfer
    For i = 1 to 5 step 1
        DatosTransmitir = DatosRecibidos
    next i
    'MAX485 or 75176 in write mode
    WR = 1
    For i = 0 to 5 step 1
        'Send data byte to byte
        Usart_Write(DatosTransmitir)
        'Wait until the byte is send
        While TXSTA.1 = 0
        Wend
    next i
    'MAX485 or 75176 in read mode
    WR = 0
End sub

'Receibe data procedure
Sub Procedure RecibeInformacion
    For i = 0 to 5 step 1
      'Over wait variable counter reset
      WatchDog = 0
      'Is the byte ready ??
      While Pir1.5 = 0
         Inc(WatchDog)
         If WatchDog = 10000 Then
            'Data Transfer error, too much time waiting
            RCREG = 0
            Exit
         End If
      Wend
      'Read the data byte receibed and store in variable
      DatosRecibidos = Usart_Read
      RCREG = 0
    Next i
   
    'Check if the receibed data is for this device
    If DatosRecibidos[0] = Direccion Then
       TransmiteDatos
    End if
End sub

main:
Usart_Init(19200)

'endlees loop
while true
    'MAX485 or 75176 in read mode
    WR = 0
    If Usart_Data_Ready = 1 then
    ' If PIR1.5 = 1 Then
      RecibeInformacion
    End if
wend
end.
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC