|
|
View previous topic :: View next topic |
Author |
Message |
Sebastian20000
Joined: 09 Nov 2007 Posts: 12
|
I/O configuration |
Posted: Sat Nov 17, 2007 12:09 pm |
|
|
Hi,
I use CCS v 4.042.
In the pic wizard i can configure if the Pins are
input or output.
Does this configuration have any effect on my
data: 16xxx.h or the data xx.h or the xx.c
Because if I configure for example PIN_A01 one time
as input and another time as output, it doesn´t have
an effect in the source code!
Both times in the 16xx.h "#define PIN_A0 40"
is active... if input or output, both the same.
Sebastian |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Nov 17, 2007 2:07 pm |
|
|
The wizard will never change the ".H" file, and you should not change it.
All PIC pins are configured as inputs during power-on reset. This is done
by the PIC hardware. When a program is running, some or all of the
pins can be changed into outputs by using lines of code. They can also
be changed back into input pins at any time, under program control.
In the program below, pin B0 is made into an output pin. This is done
automatically by the output_xxx() function. The pin is also set to a
high or low state, depending on whether you use output_high() or
output_low().
Code: |
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
//===================================
void main()
{
while(1)
{
output_high(PIN_B0);
delay_ms(500);
output_low(PIN_B0);
delay_ms(500);
}
} |
If you want to use the pin as an input, then use the input() function.
The compiler will automatically set the pin as an input before it reads it.
Code: |
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
//===============================
void main()
{
int8 value;
value = input(PIN_B0);
while(1);
} |
This is why the CCS compiler is easy to use for students. You don't
have to worry about how to set the TRIS. Just use the CCS pin i/o
functions and the compiler will automatically set the correct TRIS for you. |
|
|
jjude
Joined: 12 Nov 2007 Posts: 37
|
|
Posted: Sun Nov 18, 2007 2:57 am |
|
|
Code: |
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
//===============================
void main()
{
int8 value;
output_high(PIN_B1);
value = input(PIN_B0);
while(1);
} |
How i change code if i need "fast_io"? |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|