;***************************************************************************** ; ; File: ev_comms.asm ; ; Description: ; ; Functions: ; ; Usage Notes: ; ; History: ; 0/0/98 - V0.0 Created ; ;***************************************************************************** ; #ifndef _EV_COMMS_ASM_ #define _EV_COMMS_ASM_ ;----------------------------------------------------------------------------- ;***************************** INCLUDE FILES ********************************* ;----------------------------------------------------------------------------- ; LIST P=16C74A ; #include p16C74a.inc ; Processor constants ; ; ERRORLEVEL -302 ;remove message about using proper bank ; ;----------------------------------------------------------------------------- ;***************************** CONSTANT DEFINITIONS ************************* ;----------------------------------------------------------------------------- ; ; ; Serial Port Setup definitions ; #define TX_SETUP TX_BAUD_HIGH | TX_MODE_ASYNCH | TX_ENABLE_TX ; #define RX_SETUP RX_CONTINUOUS_RX | RX_ENABLE_RX ; #define BAUD_SELECTED BAUD_9600 ; ; ; ------- on-chip definitions do not change ---- ; ; Control register bit definitions ; #define TX_9_BIT_ENABLE 0x40 #define TX_ENABLE_TX 0x20 #define TX_MODE_ASYNCH 0x00 #define TX_BAUD_HIGH 0x04 ; #define RX_ENABLE_RX 0x80 #define RX_9_BIT_ENABLE 0x40 #define RX_CONTINUOUS_RX 0x10 ; #define BAUD_300 D'300' #define BAUD_1200 D'1200' #define BAUD_2400 D'2400' #define BAUD_9600 D'9600' #define BAUD_19200 D'19200' #define BAUD_38400 D'38400' #define BAUD_57600 D'57600' #define BAUD_76800 D'76800' #define BAUD_115200 D'115200' ; ; Baud Rate calcuations ; ; baudrate = Fosc / (16 ( X + 1 ) ; (baudrate * 16) / Fosc = 1 / ( X + 1 ) ; Fosc / (baudrate * 16 ) = ( X + 1 ) ; ; Note: Multiply by 10, add 5 and divide by 10 rounds to closest integer ; ; #if ( TX_SETUP & TX_BAUD_HIGH ) ; ;// TX_BAUD_HIGH uses divide by 16 prescaller for less baud rate error and better ;// sampling of received data ; #define BAUD_REG_VALUE ((((( CLOCK_FREQ * D'1000' * D'10' ) / ( BAUD_SELECTED * D'16' )) + D'5')/D'10') - D'1') ; #else ; ; // For slower baud rates ; #define BAUD_REG_VALUE ((((( CLOCK_FREQ * D'1000' * D'10' ) / ( BAUD_SELECTED * D'64' )) + D'5')/D'10') - D'1') #endif ; ;----------------------------------------------------------------------------- ;***************************** INTERNAL VARIABLES ************************* ;----------------------------------------------------------------------------- ; RamBank1 UDATA ; FSR_temp RES 1 ; // buffer for fsr during interrupt ; SEC_EV_COMMS CODE ;----------------------------------------------------------------------------- ;***************************** INTERFACE FUNCTIONS ************************* ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; ; Function: CommsInit ; ; Description: Setup on-chip USART peripherial for serial Comms interface ; ; Parameters: none ; ; Returns: nothing ;----------------------------------------------------------------------------- ; CommsInit: ; void CommsInit( void ) ; ; { banksel SPBRG ; movlw BAUD_REG_VALUE ; SPBRG = BAUD_SETUP; movwf SPBRG ; ; ; banksel TXSTA ; movlw TX_SETUP ; TXSTA = TX_SETUP; movwf TXSTA ; ; ; banksel RCSTA ; movlw RX_SETUP ; RCSTA = RX_SETUP; movwf RCSTA ; ; ; // enable interrupts for Rx banksel PIE1 ; bsf PIE1, RCIE ; RCIE = 1; ; ; banksel PORTA ; ; ; return ; ; ; } ; ;----------------------------------------------------------------------------- ; ; Function: CommsRxSI ; ; Description: Interrupt for Serial data received ; ; Parameters: none ; ; Returns: nothing ;----------------------------------------------------------------------------- ; CommsRxSI: ; void CommsRxSI( void ) ; ; { banksel FSR_temp ; // MONITOR Reporter! \\ movfw FSR ; movwf FSR_temp ; push( FSR ); ; ; banksel RCREG ; // read Rx register movfw RCREG ; ; ; movwf FSR ; wTemp = *RCREG; movfw INDF ; ; ; // transmit contents of address banksel TXREG ; TxREG = wTemp; movwf TXREG ; ; ; banksel FSR_temp ; movfw FSR_temp ; pop( FSR ); movwf FSR ; ; ; ReturnInt ; ; ; ; ;----------------------------------------------------------------------------- ;***************************** INTERNAL FUNCTIONS ************************* ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ;***************************** END OF FILE ********************************** ;----------------------------------------------------------------------------- #endif end