CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Output assumption

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mcad



Joined: 25 Nov 2007
Posts: 48

View user's profile Send private message

Output assumption
PostPosted: Sun Nov 25, 2007 2:55 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Nov 25, 2007 3:29 pm     Reply with quote

because the compiler set the tris for you automatically see #use standard_io in the manual.

Gary
mcad



Joined: 25 Nov 2007
Posts: 48

View user's profile Send private message

PostPosted: Sun Nov 25, 2007 3:51 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Nov 25, 2007 4:13 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Nov 25, 2007 4:35 pm     Reply with quote

Thanks very very much sir
This really helped me
Regards
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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