PDA

View Full Version : USART TXREG Problems



BigH
- 10th January 2006, 23:08
Hi Its me again

I am using Oshonsoft PIC Simulator IDE v5.33 to Monitor the Hardware UART for the Following Code. I only get an Output When I Execute the HSEROUT and I haven't a clue why this is, any Ideas Please

DEFINE USART_TXSTA 20h
DEFINE USART_RCSTA 90h
DEFINE USART_BAUD 9600
DEFINE USART_SPBRG 1

REPEAT
UNTIL PIR1.4 = 1
TXREG = "A"

REPEAT
UNTIL PIR1.4 = 1
TXREG = "B"

REPEAT
UNTIL PIR1.4 = 1
TXREG = "C"

REPEAT
UNTIL PIR1.4 = 1

' HSEROUT ["D"] 'I Get NO Output at All Until I Include HSEROUT When I the Expected Output "ABCD"

LOOP:
NOOP
GOTO LOOP

mister_e
- 11th January 2006, 00:01
There's no USART_XXX define in PBP.

you can even write..
TXSTA=$20
RCSTA=$90
SPBRG=15
this will do the same thing as
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_SPBRG 15 ' 9600 Bauds

If you don't use HSERIN/HSEROUT you MUST write to the register directly as i already wrote in the example i post to you yesterday.

Be sure of your SPBRG value... it's important and it's different for every crystal speed and baudrate. look the datasheet for that AND/OR use the calc i did in attachement.



REPEAT
UNTIL PIR1.4 = 1
TXREG = "A"

??????

Did you really look the example i posted before?

BigH
- 11th January 2006, 01:30
Hi

Its working, the confusion was caused by the DEFINE. Its seems with my compilier PICBasic PRO the TXSTA=$20 type expession works well but the DEFINE HSER_TXSTA 20h type expression Fails to Run but Compiles without Error. Looking back I can see that I had actually got it right but I chose to use DEFINE HSER_TXSTA 20h which I later change to DEFINE UART_TXSTA 20h in desperation/frustraction after seeing a reference of this type on the Web. Again thanks for getting me back on the rails. I am off to bed now and I will get the USART Interrupt working correctly in the morning.

Regards Henry