USART interrupt not interrupting right


Results 1 to 13 of 13

Threaded View

  1. #1
    Morpheus's Avatar
    Morpheus Guest

    Unhappy USART interrupt not interrupting right

    Hi All!

    I'm working with a 16f628A

    I wrote a "simple" code, the interrupt has just to turn on a led when a 9-bit char with the 9th bit enabled is received on the usart rx port.

    the main program just make blinking a led.
    the results are that if I receive an address(8 bit char with the 9th bit set), the blinking led remains on(or off) doubling the time(2 secs instead 1), and the led that the interrupt had to turn on, remains off.

    I'll post my code.

    CODE:
    ----------------------------------------------------------------------
    INCLUDE "MODEDEFS.BAS"

    TRISA=%11110000
    TRISB=%00000010

    cmcon=7 ' predispone la portaA come I/O digitali


    'INTCON ( Interruption Control register )
    intcon.7=1 'GIE : Global Interrupt Enable bit
    intcon.6=1 'PEIE : Peripheral Interrupt Enable bit ( This bit should be set when using the CCP interruption so on )
    intcon.5=0 'T0IE : TMR0 Overflow Interrupt Enable bit
    intcon.4=0 'INTE : RB0/INT Interrupt Enable bit
    intcon.3=0 'RBIE : RB Port Change Interrupt Enable bit
    intcon.2=0 'T0IF : TMR0 Overflow Interrupt Flag bit
    intcon.1=0 'INTF : RB0/INT Interrupt Flag bit
    intcon.0=0 'RBIF : RB Port Change Interrupt Flag bit

    'definisco il registro di ricezione RCSTA
    rcsta.7=1 'SPEN serial port enable bit
    rcsta.6=1 'RX9 9-bit receive enable bit
    rcsta.5=0 'SREN single receive enable bit
    rcsta.4=1 'CREN continous receive enable bit
    rcsta.3=1 'ADDEN address detect enable bit
    rcsta.2=0 'FERR framing error bit(read only)
    rcsta.1=0 'OERR overrun error bit(read only)
    rcsta.0=0 'RX9D 9th bit of receive data (read only)


    'definisco il registro di trasmissione TXSTA
    txsta.7=0 'CSRC : Clock Source Select bit
    txsta.6=0 'TX9 : 9-bit Transmit Enable bit
    txsta.5=1 'TXEN : Transmit Enable bit
    txsta.4=0 'SYNC : USART Mode Select bit 0=asincrono
    txsta.3=0 ' N/A
    txsta.2=1 'BRGH : High Baud Rate Select bit
    txsta.1=0 'TRMT : Transmit Shift Register Status bit ( Read only )
    txsta.0=0 'TX9D : 9th bit of transmit data. Can be parity bit.


    'PIE1 ( Peripheral Interrupt Enable register ) 8Ch
    PIE1.7=0 'EEIE : EE Write Complete Interrupt Enable Bit
    PIE1.6=0 'CMIE : Comparator Interrupt Enable bit
    PIE1.5=1 'RCIE : USART Receive Interrupt Enable bit
    PIE1.4=0 'TXIE : USART Transmit Interrupt Enable bit
    PIE1.3=0 ' N/A
    PIE1.2=0 'CCP1IE : CCP1 Interrupt Enable bit
    PIE1.1=0 'TMR2IE : TMR2 to PR2 Match Interrupt Enable bit
    PIE1.0=0 'TMR1IE : TMR1 Overflow Interrupt Enable bit


    'azzera tutti i flag di interrupt
    PIR1.7=0
    PIR1.6=0
    PIR1.5=0 'azzera l'RCIF
    PIR1.4=0
    PIR1.3=0
    PIR1.2=0
    PIR1.1=0
    PIR1.0=0



    'DEFINE HSER_BAUD 38400 ' Set baud rate
    'DEFINE HSER_SPBRG 15 ' Set SPBRG directly (normally set by HSER_BAUD)

    'setta la velocità a 38800
    SPBRG.7=0
    SPBRG.6=0
    SPBRG.5=0
    SPBRG.4=0
    SPBRG.3=1
    SPBRG.2=1
    SPBRG.1=1
    SPBRG.0=1



    DEFINE OSC 10




    Enable interrupt


    i VAR WORD
    led VAR BIT
    led2 VAR BIT
    ric VAR BYTE



    on interrupt GoTo indirizzo

    GoTo ricevi


    indirizzo:

    ' HSerin [ric]'riceve un carattere da seriale
    ' IF led2=1 Then
    ' PORTA.0=0:led2=0
    ' Else
    ' PORTA.0=1:led2=1
    ' EndIF
    PORTB.7=1

    Resume


    ricevi:

    For i=1 to 65000
    Next

    IF led=1 Then
    PORTB.6=0:led=0
    Else
    PORTB.6=1:led=1
    EndIF
    GoTo ricevi

    -------------------------------------------------------------------
    /CODE


    I hope someone can help me..
    Thanks,
    Simone
    P.S. Sorry for my english!
    Last edited by Morpheus; - 1st March 2005 at 23:33. Reason: specifying the device

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 :-(
    By barkerben in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th January 2005, 13:30

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