View previous topic :: View next topic |
Author |
Message |
bauereri
Joined: 16 Jan 2004 Posts: 9
|
Help writing to port B |
Posted: Mon Jan 19, 2004 2:46 pm |
|
|
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:
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:
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
|
Re: Help writing to port B |
Posted: Mon Jan 19, 2004 2:58 pm |
|
|
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
|
|
Posted: Mon Jan 19, 2004 3:07 pm |
|
|
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
|
|
Posted: Mon Jan 19, 2004 3:13 pm |
|
|
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
|
|
Posted: Mon Jan 19, 2004 3:26 pm |
|
|
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
|
|
Posted: Mon Jan 19, 2004 3:34 pm |
|
|
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
Then PORTB would be a pointer and you would have to do this
|
|
|
|