⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rs232.c

📁 NoteBook Docking Power and Audio Switch Control using Atmel AT89S51 Chip Program by C language Com
💻 C
字号:
/***************           XXXXXX CONFIDENTIAL           ****************/
/***************                                       ****************/
/*************** Description : Use RS232 to Debug      ****************/
/***************               Code and trace          ****************/
/***************                                       ****************/
/***************     Company : XXXXXXTek Inc.            ****************/
/***************  Programmer : Steven Chu              ****************/
/***************        Date : 03/26/2007              ****************/
/**********************************************************************/

#define _C_RS232_

#include "general.h"

#ifdef _RS232_DEBUG_

/*****************************************************************************
     Function : RS232Initial_2()
  Description : Initialize the RS232 Debuger 
         Note :
    Parameter : None
       Return : None
*****************************************************************************/
void RS232Initial(void)
{
  SCON = 0x50;          /* uart in mode 1 (8 bit), REN=1 */
  BDRCON &=0xEC;        /* BRR=0; SRC=0;                 */
  BDRCON |=0x0C;        /* TBCK=1;RBCK=1; SPD=0          */
  BRL=0xFD;             /* 9600 Bds at 11.059MHz         */
  ES = 1;               /* Enable serial interrupt       */
  BDRCON |=0x10;        /* Baud rate generator run       */
  _bTxdCount = _bTxdNumber = 0;
  RI = TI = 0;                      
}

/*****************************************************************************
*     Function : RS232()                                                     *
*  Description : Serial Port Interrupt for Transfer the data                 *
*         Note : RS232Initial() must be executed finally                     *
*    Parameter : None                                                        *
*       Return : None                                                        *
*****************************************************************************/
#pragma disable
void Serial_IT(void) interrupt 4
{
  if (RI)
  {
    RI = 0;
  }
  else if(TI)                      
  {
    TI = 0;                        
    if (_bTxdCount >= _bTxdNumber)
    {
      _bTxdCount = 0;               
    }

    if (_bTxdCount == 0)
    {
      _nop_();
    }
    else if (_bTxdCount < 5)
    {
      ACC = _pbTxdTbl[_bTxdCount];
      SBUF = ACC;
      _bTxdCount++;
    }
    else
    {
      _bTxdCount = 0;
    }
  }
}

/*****************************************************************************
     Function : RS232Log(void)
  Description : Send User defined data to PC directly, for self_debug
         Note : RS232Initial_2() must be executed finally
    Parameter : None
       Return : None
*****************************************************************************/
void RS232Log(void)
{
  BYTE bCnt=2;
  if (EA) // transmit only as interrupt enable
  {
    while((_bTxdCount != 0))
    {
      if (_testbit_(_fgTimeout))
      {
        if (--bCnt <= 0)
        {
          _bTxdCount = 1;
        }
      }
    }
    
    _pbTxdTbl[0] = 0x83;
    _pbTxdTbl[1] = _bLogD1;
    _pbTxdTbl[2] = _bLogD2;
    _pbTxdTbl[3] = _bLogD3;
    _bTxdNumber = 4;

    _bTxdCount = 1; 
    ACC = _pbTxdTbl[0];             
    SBUF = ACC;
  }
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -