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 support@ccsinfo.com

set port for 16f873

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



Joined: 09 Mar 2007
Posts: 31

View user's profile Send private message

set port for 16f873
PostPosted: Wed Mar 05, 2008 11:17 pm     Reply with quote

hi.
I want to set port b as output port.
here are the code. but it doesnt work. does anybody know? it only work if output_high(PIN_Bx). I do not understand?

Code:

#byte PORTB=0x06
#byte PORTC=0x07
void main(void)
{   
while(1)
{   if (INPUT(PIN_C4))          
      output_b(0b00000001);
                  .
                  .
    
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Thu Mar 06, 2008 9:14 am     Reply with quote

At power up, all ports are inputs. You need to change the portb DIRECTION to outputs. See the SET_TRIS_B() command.
_________________
David
Ttelmah
Guest







PostPosted: Thu Mar 06, 2008 9:59 am     Reply with quote

Not true.
The default mode fo the CCS compiler, is 'standard_io' mode. In this mode, the compiler wll _automatically_ insert TRIS commands for you. It works well, and except for the overhead on speed, is perfectly reliable.
The most likely problem is something else 'not shown' in the code.
Post a runnable 'demo' program, showing the fuses, what processor is involved etc. etc.. It should be the bare minimum to show the problem (only really needs the processor selection, clock setup, fuses, and the terminations of the loops).
There is nothing wrong with what is shown, except that it is incomplete.

Best Wishes
arys



Joined: 09 Mar 2007
Posts: 31

View user's profile Send private message

PostPosted: Thu Mar 06, 2008 6:22 pm     Reply with quote

drh ; I did set_tris_b(0x00); but the output box said error. s'thing involved with declaration. Still dont know. very simple codes.

Ttelmah; here are the codes.
Code:

#define (_PCM_)
#include <16F873.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
//#use rs232(baud=2400,xmit=pin_c6, rcv=pin_c7, bits=8, ERRORS)
#byte PORTB=0x06
#byte PORTC=0x07

int8 d;
 void main(void)
{   
while(1)
{   if (INPUT(PIN_C4))             
   output_b(0b00000001);
      
         
   if (INPUT(PIN_C5))             
   output_b(0b00000010);
         
}   
}
arys



Joined: 09 Mar 2007
Posts: 31

View user's profile Send private message

PostPosted: Thu Mar 06, 2008 6:25 pm     Reply with quote

forgot to tell you. when i use
--> #include <16F877A.h>
no error in output box
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Fri Mar 07, 2008 9:07 am     Reply with quote

Quote:
Not true.
The default mode fo the CCS compiler, is 'standard_io' mode. In this mode, the compiler wll _automatically_ insert TRIS commands for you.

I was talking about what the PIC does at power up. Whether or not the compiler sets the direction for you, it still needs to be set.
_________________
David
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