View previous topic :: View next topic |
Author |
Message |
mcad
Joined: 25 Nov 2007 Posts: 48
|
Output assumption |
Posted: Sun Nov 25, 2007 2:55 pm |
|
|
Hi all,
In the following code, the ins on port d are all assumed to be output. However, there is no any tris or something else used in the program which verifies that the portB pins are all output. So, why did the programmer make this assumption ?
Code: | void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_spi(SPI_SS_DISABLED);
output_high(pin_D0);
delay_ms(500);
output_high(pin_D1);
delay_ms(500);
output_high(pin_D2);
delay_ms(500);
output_high(pin_D3);
delay_ms(500);
output_high(pin_D4);
delay_ms(500);
output_high(pin_D5);
delay_ms(500);
output_high(pin_D6);
delay_ms(500);
output_high(pin_D7);
delay_ms(500);
while(1);
} |
|
|
|
Dimlow
Joined: 24 Nov 2007 Posts: 9
|
|
Posted: Sun Nov 25, 2007 3:29 pm |
|
|
because the compiler set the tris for you automatically see #use standard_io in the manual.
Gary |
|
|
mcad
Joined: 25 Nov 2007 Posts: 48
|
|
Posted: Sun Nov 25, 2007 3:51 pm |
|
|
Hi sir,
thank you for your quick reply.
Do you mean that before writing the above code, I should write the following;#USE STANDARD_IO (D)
And, thanks to this, if I use one of the pin of the Port D via the output related functions, then the pin behaves like an output, if I use one of its pin with input related functions, then it acts as a input pin. Am I right, sir ?
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 25, 2007 4:13 pm |
|
|
Standard i/o mode is the default mode of the compiler. You don't have
to do anything to enable it. You can use the #use statement to enable
it if you want to, but because it's the default mode, you don't need to do it.
To see how the compiler creates ASM code for the Standard i/o mode,
you should make a small test program and compile it. Then look at
the .LST file to see the ASM code. Set the Build Options to make the
.LST file "symbolic" mode.
Here is an example of a small test program:
Code: |
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
//======================================
void main()
{
int8 value;
output_low(PIN_D0);
output_high(PIN_D0);
value = input(PIN_D0);
while(1);
} |
Here is part of the .LST file for the program. Notice how the compiler
automatically puts in code to set the correct TRIS, and also it puts in
code to select the correct Bank address (for 16F-series PICs).
Code: |
.................... output_low(PIN_D0);
000D: BCF TRISD.0 // Set as output
000E: BCF STATUS.RP0
000F: BCF PORTD.0
.................... output_high(PIN_D0);
0010: BSF STATUS.RP0
0011: BCF TRISD.0 // Set as output
0012: BCF STATUS.RP0
0013: BSF PORTD.0
.................... value = input(PIN_D0);
0014: BSF STATUS.RP0
0015: BSF TRISD.0 // Set as input
0016: BCF STATUS.RP0
0017: CLRF value
0018: BTFSC PORTD.0
0019: INCF value,F |
|
|
|
mcad
Joined: 25 Nov 2007 Posts: 48
|
|
Posted: Sun Nov 25, 2007 4:35 pm |
|
|
Thanks very very much sir
This really helped me
Regards |
|
|
|