View previous topic :: View next topic |
Author |
Message |
nuclear__
Joined: 24 Jan 2015 Posts: 63
|
all ways to change pin output |
Posted: Sun Dec 11, 2016 3:30 pm |
|
|
Hi there, probably the truth is out there but I cannot find it. A simple question.
Other that output_high(pin) what other way exist to set pins in boolean way?
For example how can I set a pin x high when pin y is low ( both outputs)?
Or to say that if pins x ,y (inputs) are both high,set w high too. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Dec 11, 2016 3:37 pm |
|
|
1) you can read a port and use a 'mask' to set/reset individual pins when you write to that port.
2) you need to read the port, decide if x is high, then set y. similar proceedure to above
3) simple combination logic. Any 'C101' book should explain it
the CCS manual may have examples, the examples folder probably does and of course Google can find anything !
As there are several ways to do all of this, how you do it depends on several factors. PIC type, speed reqd, available memory,etc. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 11, 2016 3:45 pm |
|
|
From the CCS manual:
Quote: |
output_bit(pin, value)
Outputs the specified value (0 or 1) to the specified I/O pin. |
Quote: |
output_float(pin)
Sets the specified pin to the input mode. This will allow the
pin to float high to represent a high on an open collector
type of connection. |
Quote: | output_drive(pin)
Sets the specified pin to the output mode. |
|
|
|
nuclear__
Joined: 24 Jan 2015 Posts: 63
|
|
Posted: Sun Dec 11, 2016 4:07 pm |
|
|
temtronic wrote: |
2) you need to read the port, decide if x is high, then set y. similar proceedure to above
. |
Can you give me an example in one statement;
I guess a= input_state(pin_a1);
And then how to use 'a' to set pin_a2? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Dec 11, 2016 4:20 pm |
|
|
output_bit(pin_a2, a);
or maybe
output_bit(pin_a2, input_state(pin_a1));
I can't try. not on compiler computer...
edit...
Code: |
33: output_bit(testled, input_state(testin));
00E6 B280 BTFSC 0xf80, 0x1, ACCESS
00E8 D002 BRA 0xee
00EA 9089 BCF 0xf89, 0, ACCESS
00EC D001 BRA 0xf0
00EE 8089 BSF 0xf89, 0, ACCESS
00F0 9092 BCF 0xf92, 0, ACCESS |
this compiles so it should work....
testled is pin a0, testin is pin a1
PIC is 18F46k22
Jay |
|
|
nuclear__
Joined: 24 Jan 2015 Posts: 63
|
|
Posted: Sun Dec 11, 2016 10:23 pm |
|
|
Thank you both guys. |
|
|
|