1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

HELP!! Pleas....PIC16F627a can't make usart receive interrupt work

Discussion in 'Embedded' started by Anbeyon, Dec 15, 2006.

  1. Anbeyon

    Anbeyon Guest

    Hi

    Can someone take a peek at the code below and see if I have enabled the
    USART on the PIC16F627A correctly please.

    All I want to do right now is set up a pic running @ 10MHz to 28800
    baud and jump to my interrupt routine when it see a char. I can't
    make it happen.
    I have done this lots f times on other PICS but am getting nowhre in
    the 627A.

    Please also see the lines reagrding TRISB - there is an errata for
    pic16f627a that mentions setting TRISB<2:1>.

    all help greatfully received - thanks




    LIST p=16F627A
    #INCLUDE <P16F627A.INC>
    __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC

    ORG 0x000
    goto START

    ORG 0x004
    goto SerialIRIRQ



    START


    call InitUart ; init uart baud rate etc....
    bsf INTCON,GIE ; enable interrupts


    MAIN


    NOP
    NOP
    NOP
    NOP
    NOP
    goto MAIN

    ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>



    InitUart ;Initialises the PIC UART for 28800 baud


    ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


    clrf INTCON
    bsf PORTB, 0x01
    bsf PORTB, 0x02
    bsf STATUS,RP0 ; SELECT REGISTER BANK 1
    clrf TXSTA ; setup transmitter
    bsf TXSTA, BRGH
    bsf TXSTA, TXEN
    clrf PIE1
    bsf PIE1, RCIE ; enable receiver interrupt

    ; setup baud rate
    movlw 0x15 ; gives 28800 baud @ 10Mhz <2% error
    movwf SPBRG


    bcf STATUS,RP0 ; SELECT REGISTER BANK 1
    clrf RCSTA ; setup
    bsf RCSTA, CREN
    bsf RCSTA, SPEN
    clrf PIR1
    bsf STATUS,RP0 ; SELECT REGISTER BANK 1
    bsf TRISB, 0x01 ; set RX as input
    bsf TRISB, 0x02 ; set tx as output
    bcf STATUS,RP0 ; SELECT REGISTER BANK 1

    return
    ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


    SerialIRIRQ ; called when UART receives byte


    ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    btfss PIR1, RCIF
    retfie

    bcf PIR1, RCIF ; clr interrupt flag
    retfie

    end
     
    Anbeyon, Dec 15, 2006
    #1
    1. Advertisements

  2. Dear Anbeyon,
    I have not checked the entire code, but it jumps into my eye that
    you have not enabled the peripherial interrupt PEIE at register INTCON.

    HTH
    Wolfgang
     
    Wolfgang Mahringer, Dec 15, 2006
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.