Hello all, Can anyone please help me to clarify several simple queries regarding asynchronous serial operation using the built in USART module of the PIC16C65. Firstly I am totally confused about the operation as described in the data sheets; for instance: under asynchronous USART operation (p101) the data sheet states that the TXIF flag bit is set when the TXREG is empty (i.e. when the data in the TXREG is moved into the TSR register) but the TXIF bit in the PIR1 register implies that the TXIF bit is set when the transmit buffer is full ? - (is the transmit buffer the same as the TXREG ?). The USART operation described on p101 also states that the TXIF flag bit cannot be cleared in software, whereas the information given on p41 regarding the set up of the PIR1 register states that the TXIF bit must be cleared in software ?. - A similar situation also exists regarding the RCIF bit ? Also in the set up of both the RCSTA and TXSTA registers, the data sheet states that the I/O lines RC7/RX and RC6/TX are configured as USART pins when the SPEN bit in the RCSTA register is set, and BOTH bit 6 and bit 7 of TRISC are SET ? - Is this correct, only I thought that with bit 6 being TX (i.e. an output pin) then TRISC bit 6 should be clear ? I have included below, two version of code which I have been struggling with for several weeks with no luck so far. Can anyone see anything wrong and please point me in the right direction ?. Many thanks: Lee Hewitt (Manchester ENGLAND) ----------------------------------------------------------------------- TITLE "UART with Interupts" SUBTITLE "Version 1.0" LIST P=16c65, R=HEX include "p16c65.inc" __config _CP_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC ;macro definitions push macro movwf w_copy ;save w reg in Buffer swapf w_copy,f ;swap it swapf STATUS,w ;get status movwf s_copy ;save it endm ; pop macro swapf s_copy,w ;restore status movwf STATUS ; / swapf w_copy,w ;restore W reg endm ;variables cblock 20 w_copy ;saved W register for interrupt handler s_copy ;saved status register for int handler RX_BYTE TX_BYTE endc org 0 goto reset org 4 push btfsc PIR1,RCIF call rx_int btfsc PIR1,TXIF call tx_int pop retfie rx_int movf RCREG,w ;Load received data into w reg movwf RX_BYTE ;Store received data in file reg REC_BYTE return tx_int movf TX_BYTE,w ;Load data for transmission movwf TXREG ;Transmit the data when TXREG is loaded return reset: movlw b'10000000' ;Disable weak pull-ups on Port B option movlw 00h movwf PORTA movlw 000h tris PORTA movlw 00h movwf PORTB movlw 00h tris PORTB movlw 00h movwf PORTC movlw b'10000000' ;pin 7, RX=i/p; pin 6, TX=o/p tris PORTC movlw 00h movwf PORTD movlw TRISD movlw 00h movwf PORTE movlw TRISE movlw b'11000000' ;Enable GIE and PEIE interupts movwf INTCON movlw b'00110000' movwf PIE1 ;Enable USART RX and TX interupts call init_uart loop movlw A'a' movwf TX_BYTE goto loop ;Keep sending ASCII 'a' init_uart bsf STATUS,RP0 ;Select bank 1 bcf STATUS,RP1 movlw .5 movwf SPBRG ;Select 9600 Baud movlw 0xA0 movwf TXSTA bcf STATUS,RP0 ;Select page 0 movlw 0x90 movwf RCSTA return end ------------------------------------------------------------------- TITLE "UART Without Interupts" SUBTITLE "Version 1.1" LIST P=16c65, R=HEX include "p16c65.inc" __config _CP_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC ;variables cblock 20 RX_BYTE TX_BYTE endc org 0 goto reset reset: movlw b'10000000' ;Disable weak pull-ups on Port B option movlw 00h movwf PORTA movlw 000h tris PORTA movlw 00h movwf PORTB movlw 00h tris PORTB movlw 00h movwf PORTC movlw b'10000000' ;Pin 7, RX=i/p; pin 6, TX=o/p tris PORTC movlw 00h movwf PORTD movlw TRISD movlw 00h movwf PORTE movlw TRISE clrf INTCON ;Disable all interupts clrf PIE1 ;Disable all peripheral interupts clrf PIE2 ;Dissable all CCP interupts ;Initialise USART bsf STATUS,RP0 ;Select bank 1 bcf STATUS,RP1 movlw .5 movwf SPBRG ;Select 9600 Baud movlw 0xA0 movwf TXSTA bcf STATUS,RP0 ;Select page 0 movlw 0x90 movwf RCSTA loop movlw A'a' movwf TX_BYTE ;poll for received byte btfsc PIR1,RCIF movf RCREG,w ;Load received data into w reg movwf RX_BYTE ;Store received data in file reg REC_BYTE ;poll for transmit byte (TXREG full) btfsc PIR1,TXIF movf TX_BYTE,w ;Load data for transmission movwf TXREG ;Transmit the data when TXREG is loaded end