PDA

View Full Version : Hserin/Serin force PIC to reset???



mister_e
8th May 2005, 10:58
Hi all, i'm trying to help on another thread BUT i'm having some trouble with those lines...


DEVICE=16F877
xtal=4
BOOTLOADER=TRUE
HSERIAL_BAUD = 9600
HSERIAL_RCSTA = $90
HSERIAL_TXSTA = $24
HSERIAL_CLEAR = ON
TRISC=%10000000
DIM PinToSetClear as byte
hSerOut ["Hello!!!",13,10]
Main:
hSerOut ["root@pico # ",13,10]
DELAYMS 100
hSerIn [dec PINTOSETCLEAR]
hserout ["received data ",dec pintosetclear]
GoTo Main


what's happening? it place PIC in an endless loop displaying always the two first Hserout content and sometime it take the data sended within the IDE serial comm windows. I also tried with SERIN. Also tried to program another PIC without the Bootloader... still the same.

For sure it's a compiler problem. I try the same code(yep with slight modification) with another compiler and it's working just fine. OR it's a default setting that i can't see as i'm probably comming blind with the age.

I'm actually evaluating Proton using the lite demo version. Is it a limitation? if so it should be listed. Case not a demo version problem?

any idea?

Tim
8th May 2005, 13:08
Steve

I have tried your code (with a slight modification) and find nothing wrong!

The modification I made is the line hSerIn [dec PINTOSETCLEAR]
to hSerIn [PINTOSETCLEAR]
You have to send a series of chars in the range "1" - "0" followed by a char not in that range

I quote from the manual



The HRSIn command provides a modifier, called the decimal modifier, which will interpret this for us. Look at the following code: -

DIM SERDATA AS BYTE
HRSIn DEC SERDATA

Notice the decimal modifier in the HRSIn command that appears just to the left of the SERDATA variable. This tells HRSIn to convert incoming text representing decimal numbers into true decimal form and store the result in SERDATA. If the user running the terminal software pressed the "1", "2" and then "3" keys followed by a space or other non-numeric text, the value 123 will be stored in the variable SERDATA, allowing the rest of the program to perform any numeric operation on the variable.

Without the decimal modifier, however, you would have been forced to receive each character ("1", "2" and "3") separately, and then would still have to do some manual conversion to arrive at the number 123 (one hundred twenty three) before you can do the desired calculations on it.

The decimal modifier is designed to seek out text that represents decimal numbers. The characters that represent decimal numbers are the characters "0" through "9". Once the HRSIn command is asked to use the decimal modifier for a particular variable, it monitors the incoming serial data, looking for the first decimal character. Once it finds the first decimal character, it will continue looking for more (accumulating the entire multi-digit number) until is finds a non-decimal numeric character. Remember that it will not finish until it finds at least one decimal character followed by at least one non-decimal character. To illustrate this further, examine the following examples (assuming we're using the same code example as above): -


If this does not solve your problem ask again.

mister_e
8th May 2005, 17:58
Hi Tim, yeah i know. I also tried without any modifier... and those will make you laugh... do the same endless loop....


DEVICE=16F877
xtal=4
HSERIAL_BAUD = 9600
HSERIAL_RCSTA = $90
HSERIAL_TXSTA = $24
HSERIAL_CLEAR = ON
TRISC=%10000000
StupidLabel:
hSerOut ["Hello!!!",13,10]
Main:
goto main



DEVICE=16F877
xtal=4
StupidLabel:
SerOut PORTc.6,84, ["Hello!!!",13,10]
Main:
goto main


and this one is much than funny... while i place PORTB.7 to low, it send me the Text message


DEVICE=16F877
xtal=4
option_reg.7=0 ' enable internall pull-up
StupidLabel:
while portb.7=1
wend
SerOut PORTc.6,84, ["Hello!!!",13,10]
Main:
goto main


any idea now :)

Tim
8th May 2005, 18:11
Steve

I'm not sure what the problem you are seeing is!!!

The only thing I can think might be that your pic has the WDT on and that is reseting it. Try this:-



Device=16F877
XTAL=4
HSERIAL_BAUD = 9600
HSERIAL_RCSTA = $90
HSERIAL_TXSTA = $24
HSERIAL_CLEAR = On
Declare WATCHDOG = On
TRISC=%10000000
StupidLabel:
HSerOut ["Hello!!!",13,10]
Main:
clrwdt
GoTo Main

mister_e
8th May 2005, 18:29
oh my god! i wasn't expecting something like that. Thanks, it work!

Something to remind with PROTON i guess.