Re: Toggle line between two PIC's
Hi Wayne, from your example here my comment:
Code:
Toggle line w/pullup
PIC1 5VDC PIC2
TrisC.1=1
..
!
TrisC.1=1
PortC.1=1 PortC.1=1
Here you have the two pins floating, since both ends are set as input. To have this approach working you need to add a 10K resistor from Vdd to the pins in order to pullup the system via hardware. (Recommended)
Once you place a pin as an input via tris register you do not need any extra command, since the pin is an input and will stay an input till the following tris setting.
Now let assume you have your 10K resistor pulling up the line and both pics pins as an input, if you check the line state both pics will report portC.1 = 1 (state high)
Now let assume you want pic 1 pulldown the line then you have to use the tris register to change the pin of pic 1 from an input to an output.
TrisC.1 = 0
Now the pin on portC.1 of pic 1 is an output, but you want to drain all the current via this pin in order to be able to detect the change of state. To do that you must place the output to 0 (ground)
PortC.1 = 0
With this instruction you have surely grounded the pin of pic 1 and the reading in the input pin of pic 2 now is 0, since all the current the 10K resistor can supply is drained by the pin of pic 1.
Now if you want to put high again the line all you need to do is to remove the short generated by the pic 1, and the best way is to turn it again into an input.
TrisC.1 = 1
Now pin on portC.1 of pic 1 is an input and cannot drain the current of the 10K so the line return to Vdd value and you could check it with both pics (1 and 2)
Naturaly you have to Repeat the commands for pic 2 if you want to pulldown from that side.
Hope this will help
Cheers
Al.
All progress began with an idea
Bookmarks