;********************************************************************* ; * ; Tutorial 7 ASYNCHRONOUS USART * ; * ;********************************************************************* ;* TARGET PIC16F877 ;********************************************************************* ; ;********************************************************************* ;* @version 0.1, 27 September 2001 ;* @author James Caska ;********************************************************************* list p=16F877 #include ORG .0 GOTO INIT ORG .4 INTERRUPTHANDLER WaitForTXRegister BTFSS PIR1,TXIF GOTO WaitForTXRegister MOVF RCREG,W ;Get the Receive Byte MOVWF PORTB MOVWF TXREG ;Echo the Receive Byte onto TXREG BCF PIR1,RCIF ;Clear the Receive Interrupt RETFIE INIT ;========================================== ;Autogenerated configuration code PIC16F877 ;Config Wiz V0.1, www.virtualbreadboard.com ;========================================== ;======Begin PORT Configuration BSF STATUS, RP0 ;PORT TRIS Registers are on page 1 ;======PORT C MOVLW .128 ;PORTC Configuration Bits MOVWF TRISC MOVLW .0 MOVWF TRISB BCF STATUS, RP0 ;Restore Page0 ;========================================== ;Autogenerated configuration code PIC16F877 ;Config Wiz V0.1, www.virtualbreadboard.com ;========================================== ;=======Set up USART for asynchronous comms USART.ASYNCH.Config BSF STATUS,RP0 ;Bank1 MOVLW .25 ;9.6(9.615)K@4Mhz MOVWF SPBRG BCF TXSTA,SYNC ;Clear for Aysynchronous mode BSF TXSTA,BRGH ;baud rate high speed option BSF TXSTA,TXEN ;enable transmission BCF STATUS,RP0 ;Bank0 BSF RCSTA,CREN ;enable reception BSF RCSTA,SPEN ;enable serial port BSF STATUS,RP0 ;Move to Page 1 to set the Receive BSF PIE1,RCIE ;enable the Receive Interrupt BCF STATUS,RP0 ;Move back to return in Bank0 ;RETURN BSF INTCON,PEIE ;Enabled Peripheral Interrupt BSF INTCON,GIE ;Enabled GLobal Interrupts MAIN GOTO MAIN END