-
is hserin slow?
I am attempting to learn how to use serial communications
using the hardware serial port (16f627A) to receive a byte of data
but it seems to slow my program. The data looks clean (no noise).
I was expecting the hserin to quickly read the receive register.
can skip hserin and I read the rcreg directly? Do I need a interrupt?
Is there a better way?
DEFINE HSER_CLROERR 1 ' Automatically clear over-run errors
define HSER_BAUD 2400
RCIF VAR PIR1.5
command VAR
reponse VAR
loop:
if RCIF then
Hserin [command]
if command = 120 then
hserout [reponse] ' respond with data
endif
gosub refresh segment display
gosub read keypad
goto loop
or
loop:
if RCIF then
command=rcreg
if command = 120 then
hserout [reponse] ' respond with data
endif
gosub refresh segment display
gosub read keypad
goto loop
Thanks,
Mark
-
You forgot DEFINE TXSTA and DEFINE RCSTA stuff. But indeed you can read RCREG directly of course you can. will it be faster??? can't say.
Here's a link for you
http://www.picbasic.co.uk/forum/show...1&postcount=11
-
Thanks Steve!
Is RCREG 2 bytes?
I only have 1 byte to send, Should I always send 2 bytes
and always read 2 bytes?
Thanks,
Mark
-
Hi,
I think that RCREG can only "hold" 2 bytes.
If you don't retrieve your data before that 3rd byte comes along, you get an overrun or something. It probably just kicks the first byte it received "off the end".
:)
-
YUP! RCREG is a 2 byte buffer. This help to miss character.
You don't need to read always 2 bytes ... well yes and no. Just make a check if the RCREG is now empty will suffice.
and you just need to send 1 bytes at the time as TXREG is a single 1 byte register.
HTH
-
2 Attachment(s)
Here is a couple attached demo programs that might help,written for the 16F877.Modify for you needs.One uses the on interrupt command and the other the interrupt flag.
-
Thank You all!
I was frustrated and a little weary but your suggestions were
timely and very helpful. My serial communications are working now.
Reading RCIF & RCREG appear much faster than HSERIN.
Thanks,
Mark
-
It's like many built-in function.
HSERIN/HSEROUT
HPWM
ADCIN
are some in the list. When you need for speed, the best way is still acess the internal register. It also produce tighter code. Built-in function are great when you don't want to break your nuts with data handling and ... and ... and.. well you know what i mean ;)