Sidekick domain is published.
Bookmark it, right now.
Entire Forum
This board
This topic
Members
Entire Site
Home
Contact Us
Help
Search
GoogleTagged
Donations
Login
Register
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
April 29, 2024, 11:03:57 11:03
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Sonsivri
>
Electronics
>
Pic Basic Languages
(Moderator:
bbarney
) >
Try This
Pages: [
1
]
« previous
next »
Print
Author
Topic: Try This (Read 2928 times)
0 Members and 1 Guest are viewing this topic.
Shinta
Newbie
Offline
Posts: 21
Thank You
-Given: 20
-Receive: 3
Try This
«
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
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Electronics
-----------------------------
=> Projects
=> Pic Basic Languages
=> Pic C Languages
=> AVR, 8051 Family and ARM Area
=> RTOS
=> Artificial Intelligence (AI) & Robotics
=> Hardware and Tools
=> General Electronics
-----------------------------
Computers
-----------------------------
=> Internet Scripting Languages
=> Graphics and CAD
-----------------------------
Announcements and Rules
-----------------------------
=> Help & Rules
===> English
===> Arabic
===> French
===> Italian
===> Persian
===> Portuguese (Brazilian)
===> Spanish
===> Swedish
===> Turkish
=> Announcements
-----------------------------
Others
-----------------------------
=> General
=> Entertainment
=> Suggest Forum Content
=> Holiday and Greetings
=> Testing Forum
=> Invitation Request
Loading...