- //soft UART
- //new bryan Jan. 23, 2007
- //
- #include "includeH.h"
- unsigned char SoftUartRxOneFrame(void)
- {
- unsigned char ucGeneralCount=0,ucSoftUartRxData=0;
- while ((SOFTUART_PORT_IN & bitSOFTUARTRX) == bitSOFTUARTRX)//wait start bit Low
- {
- if ((gucGeneralStatus & bitModemActive) == bitModemActive)
- break;
- if (((KEY_PORT_IN & bitKeyRingNumDec) != bitKeyRingNumDec) ||
- ((KEY_PORT_IN & bitKeyRingNumAdd) != bitKeyRingNumAdd) ||
- ((KEY_PORT_IN & bitKeyAutoMode) != bitKeyAutoMode) ||
- ((KEY_PORT_IN & bitKeyManualMode) != bitKeyManualMode)) //||
- //((KEY_PORT_IN & bitKeySendFaxSignal) != bitKeySendFaxSignal))
- break;
- }
- if ( (SOFTUART_PORT_IN & bitSOFTUARTRX) != bitSOFTUARTRX)
- {
- delay1us(6);//SoftUartDelay();
- for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
- {
- delay1us(2);//SoftUartDelayHalf();
- ucSoftUartRxData=ucSoftUartRxData>>1;
- if ((SOFTUART_PORT_IN & bitSOFTUARTRX) == bitSOFTUARTRX)
- ucSoftUartRxData |= BIT7;//BIT7;//(1<<ucGeneralCount);//set Rx bit
- else
- {ucSoftUartRxData &= ~BIT7;__no_operation();__no_operation();__no_operation();}//~BIT7;//~(1<<ucGeneralCount);//set Rx bit
- delay1us(2);//SoftUartDelayHalf();
- __no_operation();
- __no_operation();
- __no_operation();
- __no_operation();
- __no_operation();
- }
- //delay1us(6);
- while ((SOFTUART_PORT_IN & bitSOFTUARTRX) != bitSOFTUARTRX) //wait stop bit High
- {
- if ((SOFTUART_PORT_IN & bitSOFTUARTRX) == bitSOFTUARTRX)
- break;
- gucFrhErrorStatus=0x00;//
- if (gwTimeOverflowCount++ == 0xffff)
- {gucFrhErrorStatus=0x03;gwTimeOverflowCount=0;break;}
- }
- //delay1us(6);//SoftUartDelay();
- }
- return ucSoftUartRxData;
- }
- void SoftUartTxOneFrame(unsigned char ucSoftUartTxData)
- {
- unsigned char ucGeneralCount=0;
- __disable_interrupt();
- SOFTUART_PORT_OUT &= ~bitSOFTUARTTX; //reset Tx bit
- delay1us(7);//115 9600//57 19200//17 57600 //7 115200
- //__no_operation();
- //__no_operation();
- //__no_operation();
- //delay1us(8);
- for (ucGeneralCount=0;ucGeneralCount<8;ucGeneralCount++)
- {
- if ((ucSoftUartTxData & BIT0) == BIT0)
- {SOFTUART_PORT_OUT |= bitSOFTUARTTX;} //set Tx bit
- else
- {SOFTUART_PORT_OUT &= ~bitSOFTUARTTX;__no_operation();__no_operation();__no_operation();} //reset Tx bit
- delay1us(6);//115 9600 //56 19200//16 57600 //6 115200
- //__no_operation();
- __no_operation();
- ucSoftUartTxData=ucSoftUartTxData>>1;
- }
- __no_operation();
- __no_operation();
- SOFTUART_PORT_OUT |= bitSOFTUARTTX; //set Tx bit
- delay1us(7);//115 9600 //17 57600//7 115200
- _EINT(); //enable interrupt
- }
- void SoftUartDelay7us(void)
- {
- unsigned wGeneralCount=0;
- //BauRate1200 wGeneralCount<831 BauRate9600 wGeneralCount<96 BauRate115200 6 42 19200
- for (wGeneralCount=0;wGeneralCount<4;wGeneralCount++)
- {
- __no_operation();
- }
- }
- void SoftUartDelay8p7us(void)
- {
- unsigned wGeneralCount=0;
- //BauRate1200 wGeneralCount<831 BauRate9600 wGeneralCount<96 BauRate115200 6 42 19200
- for (wGeneralCount=0;wGeneralCount<4;wGeneralCount++)
- {
- __no_operation();
- __no_operation();
- }
- }
- void SoftUartDelay(void)
- {
- unsigned wGeneralCount=0;
- //BauRate1200 wGeneralCount<831 BauRate9600 wGeneralCount<96 BauRate115200 6 42 19200
- for (wGeneralCount=0;wGeneralCount<96;wGeneralCount++)
- {
- __no_operation();
- }
- }
- void SoftUartDelayHalf(void)
- {
- unsigned wGeneralCount=0;
- for (wGeneralCount=0;wGeneralCount<48;wGeneralCount++)//BauRate1200 wGeneralCount<831 BauRate9600 wGeneralCount<96
- {
- __no_operation();
- }
- }
- void Delay1us(void)
- {
- __no_operation();
- __no_operation();
- __no_operation();
- __no_operation();
- __no_operation();
- __no_operation();
- __no_operation();
- __no_operation();
- }