Usart interrupt


Closed Thread
Results 1 to 4 of 4

Thread: Usart interrupt

  1. #1
    tht123's Avatar
    tht123 Guest

    Default Usart interrupt

    Hello everybody,

    After many search, I hope find here a solution to my problem.

    I'm using the PIC16F877, and I would like

    1) Receive a byte through USART interrupt,
    2) During these interrupt sendback a byte with the usart.

    The first point here above can be esaly done, eg :
    http://www.picbasic.co.uk/forum/arch...hp/t-3068.html

    But how can I perform the 2nd point because the HSERIN and HSEROUT command are not available in case of using the hardware serial interrupt???

    May be by using the simple software serout command, but is not the realy best method.....

    WKR, thony

  2. #2
    JohnMacklo's Avatar
    JohnMacklo Guest


    Did you find this post helpful? Yes | No

    Default

    Try using DT instant interrupts.
    It worked for me.

    http://darreltaylor.com/DT_INTS-18/home.html

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Will this work??
    Code:
    DISABLE
    USART_INT:
        RCSTA=0   ' disable serial port
             'bla bla bla                     
        RCSTA=$90   ' re-start serial port
    HSEROUT SOMETHING
        RESUME                  
    ENABLE
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Sep 2009
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Hello.

    I suggest that you use mr. Darrel Taylor's (fantastic) instant interrupts as mr. JohnMacklo proposed, but not from the link he provided which is for 18Fs only and you're using 16F. Instead start here: http://www.picbasic.co.uk/forum/showthread.php?t=3251

    Here is an example of using mr. Taylor's USART interrupt to receive and send received, one byte at a time. However that is not the proper way to do it, you should use ISR only to collect data and get out of it as soon as possible. One of the usual methods is to create a buffer and fill it in ISR, and process received data when you can spare some time. It all depends on what you need. If you can tell us what would you like to achieve maybe we could assist you a little bit more.

    Code:
     
    DEFINE OSC 20
    @ __CONFIG _HS_OSC & _WDT_ON & _PWRTE_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_ENABLE_ON & _DEBUG_OFF & _CP_OFF
    
    
    include "dt_ints-14.bas"
    
    
    RCSTA = $90		' Enable serial port & continuous receive
    TXSTA = $24		' Enable transmit, BRGH = 1
    SPBRG = 129		' 9600 Baud @ 20MHz, 0.16%
    DEFINE HSER_CLROERR 1	' Clear overflow automatically
    
    
    x	var byte
    
    
    ADCON0=%11000000
    ADCON1=%00000111
    
    porta=0
    portb=0
    portc=0
    portd=0
    porte=0
    trisa=%00010000
    trisb=%00000000
    trisc=%10000001
    trisd=%00000000
    trise=%00000000
    pause 200
    
    
    
    
    ASM
    INT_LIST  macro    ; IntSource,   Label,  Type, ResetFlag?
    	INT_Handler	RX_INT,  _IHINFO,  asm,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
        INT_ENABLE   RX_INT
    ENDASM
    
    
    
    MAIN:
    'do something here...
    goto MAIN
    
    
    
    
    RX_ISR:
    x=rcreg
    txreg=x
    @ INT_RETURN
    In RX_ISR you can use HSERIN/OUT instead of directly reading RCREG and writting to TXREG, but accesing registers directly is a little bit faster I think. At least it uses less code space.

Similar Threads

  1. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  2. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  3. USART interrupt in PIC16F877A
    By amindzo in forum General
    Replies: 7
    Last Post: - 26th August 2006, 18:51
  4. PIC Basic PRO 16F877 USART Interrupt TX
    By BigH in forum Serial
    Replies: 8
    Last Post: - 9th January 2006, 23:26
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 1

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