sci.c
资源名称:de8681_w.rar [点击查看]
上传用户:lilishw
上传日期:2021-05-28
资源大小:1542k
文件大小:3k
源码类别:
Modem编程
开发平台:
Visual C++
- //---------------------------------------------------------------------------------------------------
- // Project:- DE8681
- // Filename:- SCI.C
- // Description:- Routines for initialisation and use of the SCI for the PIC processor.
- // Programmer:- D.T.F
- // Version:- 2.0
- // Created:- 28th February 2002
- // Last modified:-
- //---------------------------------------------------------------------------------------------------
- // (C) Consumer Microcircuits Ltd 2002
- //
- // This firmware was designed by:-
- // Consumer Microcircuits Ltd,
- // Langford, Maldon,
- // ESSEX
- // CM9 6WG.
- // in the UK for use with CML evaluation kits only and is based on UK originated technology.
- // Please contact
- // sales@cmlmicro.co.uk
- // +44 (0)1621 875500
- // for licensing details.
- //---------------------------------------------------------------------------------------------------
- #define SCI_C
- #include "ef8681.h"
- unsigned char sci_init(unsigned long int baud, unsigned char ninebits)
- {
- int X;
- unsigned long tmp;
- /* calculate and set baud rate register */
- /* for asynchronous mode */
- tmp = 16UL * baud;
- X = (int)(FOSC/tmp) - 1;
- if((X>255) || (X<0))
- {
- tmp = 64UL * baud;
- X = (int)(FOSC/tmp) - 1;
- if((X>255) || (X<0))
- {
- return 1; /* panic - baud rate unobtainable */
- }
- else
- BRGH = 0; /* low baud rate */
- }
- else
- {
- BRGH = 1; /* high baud rate */
- }
- SPBRG = X; /* set the baud rate */
- SYNC = 0; /* asynchronous */
- SPEN = 1; /* enable serial port pins */
- CREN = 1; /* enable reception */
- SREN = 0; /* no effect */
- TXIE = 0; /* disable tx interrupts */
- RCIE = 0; /* disable rx interrupts */
- TX9 = ninebits?1:0; /* 8- or 9-bit transmission */
- RX9 = ninebits?1:0; /* 8- or 9-bit reception */
- TXEN = 1; /* enable the transmitter */
- return 0;
- }
- void sci_putByte(unsigned char byte)
- {
- while(!TXIF) /* set when register is empty */
- continue;
- TXREG = byte;
- return;
- }
- unsigned char sci_getByte(void)
- {
- while(!RCIF) /* set when register is not empty */
- continue;
- return RCREG; /* RXD9 and FERR are gone now */
- }
- unsigned char sci_checkOERR(void)
- {
- if(OERR) /* re-enable after overrun error */
- {
- CREN = 0;
- CREN = 1;
- return 1;
- }
- return 0;
- }
- #define sci_putNinth(bitnine) (TX9D = bitnine?1:0;)
- unsigned char sci_getNinth(void)
- {
- while(!RCIF)
- continue;
- return RX9D; /* RCIF is not cleared until RCREG is read */
- }
- unsigned char sci_getFERR(void)
- {
- while(!RCIF)
- continue;
- return FERR; /* RCIF is not cleared until RCREG is read */
- }