View previous topic :: View next topic |
Author |
Message |
darryl_co
Joined: 11 Nov 2015 Posts: 21 Location: India
|
Setting the pins as input or output of PIC12F675 |
Posted: Sun Nov 29, 2015 3:17 pm |
|
|
Please help me set the pins of 12F675 as input or output .
GP0 and GP3 input and rest output.This is one example
Code: | set_tris_a( 0b11111101 ); // set GP1 output, all other inputs |
How to enable pull up for inputs?
How to set all outputs to low? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
darryl_co
Joined: 11 Nov 2015 Posts: 21 Location: India
|
|
Posted: Sun Nov 29, 2015 11:23 pm |
|
|
I do have that manual. I searched it but was still not able to understand so I requested for example. The pic is 8 bit. GP0, 1,2,4,5 are input /output and GP3 is MCLR pin only input |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 30, 2015 12:09 am |
|
|
Code: | #include <12F675.h>
#fuses INTRC_IO, NOWDT, NOMCLR
#use delay(clock=4M)
//==========================
void main()
{
set_tris_a(0x09);
port_a_pullups(0x3F);
output_a(0);
while(TRUE);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19381
|
|
Posted: Mon Nov 30, 2015 1:13 am |
|
|
The only problem here is after the 'output_a(0)' statement, the port will all be set as output, except PIN_A3. So TRIS will actually be set as 0x8 at the end of the program.
Have a look at this thread:
<http://www.ccsinfo.com/forum/viewtopic.php?t=54597>
The output statement will override the earlier TRIS statement.
Understand that in general, you hardly ever actually have to set the TRIS with CCS C. If you just input from the pins you want as inputs, and output to the pins you want as output, CCS will automatically set the TRIS for you. |
|
![](templates/subSilver/images/spacer.gif) |
darryl_co
Joined: 11 Nov 2015 Posts: 21 Location: India
|
|
Posted: Mon Nov 30, 2015 11:08 am |
|
|
One More help. for the code
output_toggle(GP1);
how to get
GP2=!GP1
if gp1 is high than gp2 is low |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19381
|
|
Posted: Mon Nov 30, 2015 11:13 am |
|
|
output_bit(PIN_A2, !input(PIN_A1)); |
|
![](templates/subSilver/images/spacer.gif) |
|