Serial-In for PIC with USART


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1

    Default Serial-In for PIC with USART

    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

  2. #2
    Join Date
    Mar 2004
    Location
    UK-Midlands
    Posts
    84


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3


    Did you find this post helpful? Yes | No

    Default Serin

    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
    Attached Files Attached Files

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by amgen View Post
    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...bbcode#imgcode

  5. #5


    Did you find this post helpful? Yes | No

    Default Serial-in

    Thanx for pointing the way on posting

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

    Code:
    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     
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Similar Threads

  1. My USART problems..
    By Glenn in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 31st July 2009, 01:00
  2. Dynamic USB Serial Number (PIC18F4550)
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th July 2009, 17:03
  3. PIC18F4680 to PC via MAX232 (RS232 serial) no output
    By opticsteam1 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th April 2008, 20:39
  4. problem with USART
    By leemin in forum Serial
    Replies: 4
    Last Post: - 11th December 2006, 17:56
  5. Replies: 1
    Last Post: - 6th September 2005, 16:32

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts