PDA

View Full Version : hserout PIC pic 16F876



- 2nd February 2005, 10:30
Hello !

I would like to know if , using the define and the HESROUT instruction, it is possible to change the baud right *during* the execution of the program.

I would like to make possible the user [ me , "8-) ] to select 9600 and 19200.

Everything is ok in both speed, but i can't switch from one to another ...

It seems that new define are not allowed during execution ...

And writing to regsiter seems to confuse HSEROUT ...

If someone has an idea or a piece of could, i would be glad to read it / him

Thank a lot for helping !
Apologize for poor english , i was a bad boy at school ...
Vincent

mister_e
- 2nd February 2005, 18:00
Apologize for poor english , i was a bad boy at school ...
Vincent


don't be afraid of that...



Everything is ok in both speed, but i can't switch from one to another ...

It seems that new define are not allowed during execution ...

And writing to regsiter seems to confuse HSEROUT ...


can you something for me. I'm not sure it's gonna work but... worth a try ;)

Let's assume you have a 20MHZ crystal.

Refer to the table 10-4:
SPBRG=129 '@9600 bauds
SPBRG=64 '@19200 bauds


IMO we can change the baud rate only by changing the value of the SPBRG register.

so give a try to this snipet



DEFINE OSC 20

start:
TXSTA=$24
RCSTA=$90
SPBRG=129 '@9600 bauds
pause 100 'try to remove this pause after
HSEROUT ["comm @9600 bauds"]
TXSTA=$24
RCSTA=$90
SPBRG=64 '@19200 bauds
PAUSE 5000 'wait 5 seconds
HSEROUT ["comm @19200 bauds"]
goto start


let me know... i'm curious.

If it's working, try to define TXSTA and RCSTA only one time at the begining to see if it's also work.



DEFINE OSC 20
TXSTA=$24
RCSTA=$90

start:
SPBRG=129 '@9600 bauds
pause 100 'try to remove this pause after
HSEROUT ["comm @9600 bauds"]
SPBRG=64 '@19200 bauds
PAUSE 5000 'wait 5 seconds
HSEROUT ["comm @19200 bauds"]
goto start

Ingvar
- 2nd February 2005, 18:05
There should be no problem to switch between theese two baudrates "on the fly". All you need to do is put correct values in the SPBRG register(and perhaps bit BRGH in TXSTA). There is a table specifying SPBRG values at diffrent oscillatorspeeds. I can't help you further without knowing what crystal you're using.

- 2nd February 2005, 19:18
Hello,

thanks for helping,

my XT is a 4MHz , i will adapt value, and try what you suggest , i will let you know the results.

Thanks
Vincent

- 2nd February 2005, 21:56
Hello,

steve you are the king, your code works both 1 and 2 !

To share my experiment :

I did not use anymore the define, but i write to TXSTA and
RCSTA , i only use the autoerror clearing define, and it is ok.


The pause 100 after the change of SPBRG , is mandatory, probably the baud clock needs to get stable , without this pause the first char are lost ( maybe , 3 or 4 character at full speed simple serout like :

hserout["ABCDEFG"]

with 100ms pause, you are secure, and it is only at "initialization" not after.

Many thanks for your help, switching the baudrates has been a big moment for me !

Vincent STEINMETZ
(France , other side of sea ... )

mister_e
- 3rd February 2005, 01:32
Salut Vincent!

Great to know it's working fine now. I don't know how the *initialisation* must be, but if you can try with some other low value like

PAUSE 10
PAUSE 1
PAUSEUS 100
PAUSEUS 10
PAUSEUS 5
@ NOP ' 1usec delay @4MHZ

will be interesting to have the results...

- 3rd February 2005, 20:34
Hello steve,

I have done the tests

the minimal pause seems to be pause 10 , under this value , the three first character are lost, every time , it is not erratic but highly repeteable ...

=>I have 20Mhz pic working at 4mHz

Let me know if you need something else.

Vincent

mister_e
- 3rd February 2005, 22:54
That's perfect. Was for learning purpose. Great to know that.

thanks.