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

Help writing to port B

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



Joined: 16 Jan 2004
Posts: 9

View user's profile Send private message

Help writing to port B
PostPosted: Mon Jan 19, 2004 2:46 pm     Reply with quote

Hello,

I need a little help writing to port b. I want to drive an 8 bit DAC w/ port B, so I it would be nice to be able to write to the whole port at once. I think this should be possible, but I'm getting some compiler errors I can't resolve. I tried the following:

Code:
output_b(0x00);

and

Code:
#byte PORTB = 0x00;


The compiler was telling me that I had an 'Undefined Identifier' with both of these until I placed this is the header file:

Code:
#define PORTB 0x06


Now I still get the indentifier error using the first statement, but the second statement now produces an error that says ' A numeric espression must appear here".

Does anyone have any ideas about what I am doing wrong??

Thanks,

Eric
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Help writing to port B
PostPosted: Mon Jan 19, 2004 2:58 pm     Reply with quote

bauereri wrote:


Code:
#byte PORTB = 0x00;

Eric


Defining port b to exist at memory address 0 is a problem.
Just remove that line.
bauereri



Joined: 16 Jan 2004
Posts: 9

View user's profile Send private message

PostPosted: Mon Jan 19, 2004 3:07 pm     Reply with quote

Then what is the proper way for me to write to the port without settting each individual pin using OUTPUT_HIGH() or OUTPUT_LOW()??

Eric
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Jan 19, 2004 3:13 pm     Reply with quote

Well it should be

#byte PORTB = 0x06;

And then

PORTB = 0;

Not sure why you are having problems with output_b() unless your pic doesn't have portb. What pic are you using?
bauereri



Joined: 16 Jan 2004
Posts: 9

View user's profile Send private message

PostPosted: Mon Jan 19, 2004 3:26 pm     Reply with quote

Hi Mark,

If I place the statement ' #byte PORTB = 0x06' at the beginning of main(), and the use the 'PORTB = 0; ', the program will compile. I will have to test to see if it works the way I need it to. I am correct in thinking that I can use base 10 numbers in the 'PORTB =' statements??

I am using a PIC16F876, so there is definitly a portb. It would be great if could use the output_b() function. Are there any #use statements or anything that need to be issued before using that command??

Eric
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Jan 19, 2004 3:34 pm     Reply with quote

Yes on the base 10
Code:

PORTB = 32;
PORTB = 0x20;

are the same.

The only thing I can think of as to why the output_b() is not working is that you typed the letter "O" instead of the number "0" or that you are using the #case and did not use lower case letters for the function name.

BTW:
If you would have used
Code:

#define PORTB    6


Then PORTB would be a pointer and you would have to do this
Code:

*PORTB = 0;
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