PDA

View Full Version : how to set RCSTA



mat janssen
- 26th September 2006, 12:40
I use the pic16F876.
In my definition I want to set the RCSTA register to D0 hex.
The compiler does not like this.
When I write:
DEFINE HSER_RCSTA 90H
then it is ok
If I come to A0H or higher the compiler gives an error.
The compiler is PBP2.47
Regards
Mat

mister_e
- 26th September 2006, 15:22
EDIT: forget me if you readed the previous post version

Yeah i got issue here too. so just set all register directly whithout the DEFINEs solve the problem....BUT i didn't check what the A0 value did so, it could be normal :D

mat janssen
- 26th September 2006, 15:39
Thanks, I did it also like that. But it looks like a small buggiein the compiler!
Regards.
M

Darrel Taylor
- 26th September 2006, 16:40
Hi Mat,

To set the USART to 9-bit mode, use ...

DEFINE HSER_BITS 9

RCSTA will automatically be set to 0D0h
TXSTA will also be set to 60h

HTH,

mister_e
- 26th September 2006, 16:43
i don't know why but my attention was mostely on 'above A0' than on the real purpose ... i just saw that D0.

Too bad, there's some missing conditions in the Macro

Darrel Taylor
- 26th September 2006, 16:53
I think it would also work with a 0 before the D0h in DEFINE HSER_RCSTA.

Don't think there's anything missing. Sometimes it helps to look at the Defaults in the PBPPIC14.lib file.
;************************************************* ***************
;* Default hardware serial port values *
;************************************************* ***************

ifndef HSER_BITS
HSER_BITS = 8 ; Default to 8 bits
endif
ifndef HSER_RCSTA ; Receive register data
if (HSER_BITS != 9)
HSER_RCSTA EQU 90h ; Receiver enabled
else
HSER_RCSTA EQU 0d0h ; Receiver enabled for 9 bits
endif
endif
ifndef HSER_TXSTA ; Transmit register data
if (HSER_BITS != 9)
HSER_TXSTA EQU 20h ; Transmitter enabled
else
HSER_TXSTA EQU 60h ; Transmitter enabled for 9 bits
endif
endif

mister_e
- 26th September 2006, 17:00
Yeah right... but why the extra 0 before D0? that's another story :D

And since the 9 bit mode is probably not a common/popular use.... Anyways there's always many different solution such as set the register directly

Darrel Taylor
- 26th September 2006, 17:14
but why the extra 0 before D0?

If anything starts with a Letter, the assembler considers it to be either a Label, Variable name, or Text replacement value.

For it to know that it's a number, it has to start with a digit between 0-9. This is why Variables and Labels can't start with a number.

So any HEX numbers with A-F in the first digit must be preceeded by a 0.

In PBP, HEX numbers start with a $, so it can tell it's a number without the 0.
<br>

mat janssen
- 26th September 2006, 17:14
Thanks all of you. I think I will take the DEFINE HSER_BITS 9 Than I will not forget after a few month what I did there. And why a 0 before, I dont't know, but if they want that, I will do that.

Thanks Darrel, now I know. We were here at the same time.

mister_e
- 26th September 2006, 17:18
Thanks Darrel, it make sense now.