PDA

View Full Version : Serial-In for PIC with USART



amgen
- 10th July 2008, 15:21
I propose that since you can't know exactly when you will receive a serial in, and can't just stop and wait, a good solution is to use RCV interrupt and small asm to take in chars then raise a flag after getting X amount of chars, to then deal with in Basic ???? Not good for pics w/o USART.
Are interrupts just too difficult?

don
amgen

BobP
- 10th July 2008, 20:40
Hi amgen,

I had the time to really examine and modify the sample programs on MEL's site. There are some gems in there well worth learning from. Here is a program worth looking at:
http://www.melabs.com/resources/samples.htm#18Fpbp the program serA452.bas
If you look at it you will find this does exactly what your were talking about. It works like a dream. With simple documented changes it can have a buffer up to 127 characters. Even the ASM is easy to follow.

Worth spending a bit of time on it.

Bob

amgen
- 11th July 2008, 15:31
Hi Bob,
Thanks for that link. It turned out to be just about what I had fumbled to program a few monthes ago trying to get serin to work. The 18f chips automatically saves settings on int and replace registers with FAST RETURN, I think.
I added a "start char" and "end char" to sort of frame the incomming ASCII and know when to tell Basic to deal with received stuff.
I think the interrupt service routine only takes about 10 to20 or 30 micro seconds every time a character comes in.
Do you see improvments to this stuff?

Don
amgen

HOW do you post the code window here. Copy paste deforms the layout to just about unreadable so I just attached file???
thanks

skimask
- 11th July 2008, 15:35
HOW do you post the code window here. Copy paste deforms the layout to just about unreadable so I just attached file???
thanks

http://www.picbasic.co.uk/forum/misc.php?do=bbcode#imgcode

amgen
- 11th July 2008, 22:26
Thanx for pointing the way on posting

serin stuff, works in backround......



asm
DONSint MOVLW "|"
CPFSEQ RCREG ;CHECK FOR "|" START CHAR 7CH
GOTO no#MATCH
#MATCH LFSR FSR2,150 ;INDEX1=250...A0H START OF DATA FSR2=150
SETF _RCVok ;SET OK TO RECIEVE FLAG
GOTO OUT1
no#MATCH BTFSS _RCVok,1 ;LEAVE IF OK TO RECIEVE FLAG NOT SET
GOTO OUT1
MOVFF RCREG,POSTINC2 ;STORE RCV CHAR TO LOCATION INDEX1 ,FSR2
MOVLW 250 ;INC INDEX AUTOMATICALLY
CPFSLT FSR2L ;CHECK FOR INDEX > 250, 100 CHARS OR
GOTO OUTgo
MOVLW "~" ;CHECK FOR "~" END CHAR 7EH
CPFSEQ RCREG
GOTO OUT1
GOTO OUTgo
OUTgo SETF _DATAready ;TELL BASIC DATA READY
CLRF RCIE ;INT OFF UNTIL BASIC TAKES CHARS
CLRF _RCVok ;RCV OK OFF UNTIL # START CHAR
CLRF CREN
RETFIE FAST

OUT1 CLRF CREN ;LEAVE INT HERE IF MORE CHARS
SETF CREN
RETFIE FAST
endasm
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''