give an address to pic on rs-485 network
I'm trying to figure out how to put an address in pic by Dip Switch. What I mean is I'm trying to teach pic to determine network address 485 by changing the state of dip Switchs.
sample request:
for address 001 - dip switch will be off off off on
for address 002 - dip switch will be off off on on
and so on.
what i am missing is the true table and how to code it in picbasic.
I sure like a snip of code to understand this issue.
Does anyone have an idea?
Re: give an address to pic on rs-485 network
Hi,
Lets say you have the four switches connected to PortB.0 thru PortB.3 and that they pull their respecitve pin high when 'on'. Then all you need to is
Code:
Adress VAR BYTE
TRISB = %00001111 ' lower four bits as inputs, rest as outputs
Adress = PortB & 15
At this point the variable Adress will contain the the "value" of the dip switches as coded "in binary" and allows for a total of 16 adresses, 0-15.
In your example, the first line would be adress 1 but the second would be adress 3 when using the above code.
/Henrik.
1 Attachment(s)
Re: give an address to pic on rs-485 network
Normally rotary BCD selector switches are used.
Attachment 7220
This save the user having to work out which dip switches to set to get the required binary value.