Hi, I'm new to PIC programming and trying to write a program to send a string to the hyperterminal, through RS232 interface. After initializing RS232 communicating, the PIC can receive characters from the hyperterminal and echo back to the screen. And inside interrupt service, I can print string to the hyperterminal (In my program, I try to print "BANK" and "TEST" to the PC). However, right after initialsing the PIC, I cant send characters to PC (In my program I try to send BANK to the HT). I don't know why there is difference between sending characters to HT from within interrupt code and from "normal" code (i.e. the code not handling interrupt)? Can anybody help me with this one? Thank a lot. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; RS232 communicating LIST P=16F877, F=INHX8M #include __config _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _LVP_OFF & _BODEN_ON & _WDT_OFF & _HS_OSC & _PWRTE_ON ;--------------------------------------------------------------------------- - ;Macros to select the register bank ;Many bank changes can be optimized when only one STATUS bit changes Bank0 MACRO ;macro to select data RAM bank 0 bcf STATUS,RP0 bcf STATUS,RP1 ENDM Bank1 MACRO ;macro to select data RAM bank 1 bsf STATUS,RP0 bcf STATUS,RP1 ENDM Bank2 MACRO ;macro to select data RAM bank 2 bcf STATUS,RP0 bsf STATUS,RP1 ENDM Bank3 MACRO ;macro to select data RAM bank 3 bsf STATUS,RP0 bsf STATUS,RP1 ENDM Send macro send_char movlw send_char call _RSxmit endm ;;;;;;;;;;Variables;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; cblock 0x70 W_Temp STATUS_Temp endc ;;;;;;;;;Reset and Interrupt Vectors;;;;;;;;;;;;;;;;;;;;;;;;;; org 0x0000 ;Reset vector goto Start org 0x0004 ;Interrupt vector goto IntService ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Program begins here Start call Initial_RS232 Send 'B' Send 'A' Send 'N' Send 'K' Loop goto Loop ; Loop forever ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Initialisation subroutine Initial_RS232 clrf PIR1 clrf PIR2 ;Clear interrupt flags registers clrf PORTA clrf PORTB clrf PORTC clrf PORTD clrf PORTE ;Clear ports to output all 0's bsf STATUS, RP0 ; Set RAM Bank 1 movlw .7 movwf ADCON1 ;PortA and PortE all digital I/O clrf TRISA ;Port A all outputs clrf TRISB ;Port B all outputs movlw .192 ;Port C all outputs except for UART RX TX movwf TRISC clrf TRISD ;Port D all outputs clrf TRISE ;Port E all outputs movlw .36 ;TX On, Async mode, high speed 9600bps, 8 bit trasnmission movwf TXSTA movlw .129 ;9600bps at 20Mhz movwf SPBRG movlw .32 movwf PIE1 ;Enable USART recieve interrupt bcf STATUS, RP0 ;Set RAM Bank 0 clrf ADCON0 movlw .144 movwf RCSTA ;RX On continous recieve movf RCREG, W ;Empty USART RX FIFO movf RCREG, W movf RCREG, W movlw .192 movwf INTCON ;Set GIE and periferal interrupts return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; USART interrupts handled here IntService movwf W_Temp ; Save a copy of W swapf STATUS, W ; Swap status and save to W clrf STATUS ; Bank 0 movwf STATUS_Temp ; Save STATUS Send 'B' Send 'A' Send 'N' Send 'K' btfss PIR1, RCIF ; Check Interrupt flag goto End_Int ; If No, go to EndInt btfss RCSTA, FERR ; Check for framing error goto No_Framing_Err movf RCREG, W ; Remove the framing by reading FIFO goto End_Int No_Framing_Err btfss RCSTA, OERR ; Check if it is overun error goto Receive_data bcf RCSTA, CREN ; Remove overrun error by resetting USART nop bsf RCSTA, CREN goto End_Int clrf STATUS btfsc PIR1, TXIF ; Test for TXIF transmit interrupt ; bsf STATUS, RP0 ; Change to bank 1 if TXIF set ; btfsc PIE1, TXIE ; Test if interrupt enabled if TXIF set goto Trans_data goto End_Int Receive_data movf RCREG, W movwf PORTB ;movwf TXREG Send 'T' Send 'E' Send 'S' Send 'T' goto End_Int Trans_data clrf STATUS movlw 'T' movwf TXREG End_Int swapf STATUS_Temp, W ; Swap STATUS_TEMP into W movwf STATUS ; Move W into STATUS register swapf W_Temp, f ; Swap W_Temp swapf W_Temp, w ; Swap W_Temp into W retfie ; return from interrupt _RSxmit Bank1 _RSbusy btfss TXSTA,TRMT ; check, if previous transmission goto _RSbusy ; has been terminated Bank0 movwf TXREG ; send next char RETURN end -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body