Forums

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

Started by Anbeyon December 15, 2006
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

Dear Anbeyon,

Anbeyon wrote:

> 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.
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 -- From-address is Spam trap Use: wolfgang (dot) mahringer (at) sbg (dot) at