PDA

View Full Version : give an address to pic on rs-485 network



russellperry
- 2nd February 2014, 09:32
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?

HenrikOlsson
- 2nd February 2014, 11:30
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

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.

EarlyBird2
- 8th February 2014, 23:50
Normally rotary BCD selector switches are used.

7220

This save the user having to work out which dip switches to set to get the required binary value.