PDA

View Full Version : SEROUT2 Question ?



andybarrett1
- 12th April 2015, 16:23
Hi Thanks for reading...

I have this code :-

SERIN2 PORTC.5,813, [STR pass\4]

Reads what I expect great at 1200 Baud.... My question is how do echo what is being entered back to the operator... The above works great but I am finding I have to wait for the 4 charactors to fill before I can get it back using SEROUT2 ?

Or do I have to do them 1 at at time (1 in/ 1 out)??

Thank you for help

Andy

HenrikOlsson
- 12th April 2015, 18:05
Hi Andy,
High level PBP commands are "blocking" in nature, meaning that while they are doing their thing nothing else gets done. You're asking PBP to receive a string of four bytes so it will sit there and "receive" until 4 bytes are receieved - then it will continue with the next instruction.

So, yes, if you want to echo back characters oneby one you need to grab them one by one and send them back as they come in. If it's a human typing on keyboard this might work - or it might not. The reason is, as above, while the PIC is busy eching back the character just received it can't also receive the next character (usign SERIN/SEROUT that is).

Obviously the "best" way to handle these sort of scenarios is to use the hardware USART, if your PIC has one. Using HSEROUT on a byte by byte basis is MUCH faster then SEROUT because the all PBP needs to do is put the byte to be sent into the USARTs transmit register (if there's room). And at the same time abother byte can be coming into the receive buffer of the USART without any involvment of PBP.

So, if your PIC has a USART I suggest you switch to HSERIN/HSEROUT. Then of course you can take it one step further and use interrupts.

With that said, doing HSERIN [STR pass \4] won't allow you to echo the characters one by one as it's still blocking untill 4 bytes are received.

/Henrik.

andybarrett1
- 12th April 2015, 22:49
hi Henrik

TY for fast reply.... As I thought only one thing at a time!!

I am spoilt I work with ABB DCS systems in my day job #spoilt

So I need to find a workaround ....
I suspect it will take up a lot more memory than I have available spare

Thank you again

Andy