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

📄 sysinit.c

📁 单片机的下位端
💻 C
字号:
#include <regx52.h>

void Sys_Init(void)
{
/****************************************************************************
          EA    -    (ET2)     ES       ET1    EX1    ET0    EX0        IE
       -----------------------------------------------------------     ------  
     	  ALL   -    (T2)    SERIAL     T1     INT1   T0     INT0       0XA8
*****************************************************************************
       EA will be set at the end of the function.
****************************************************************************/   

    IE = 0x12;//ENABLE THE SERIAL AND T0 INTERUPTION

/*************************************************************************** 
           -    -    (PT2)    PS       PT1    PX1    PT0    PX0        IP
	   ----------------------------------------------------------     ------
	       -    -    (T2)   SERIAL     T1     INT1   T0     INT0       0XB8

****************************************************************************
    while the nature order is:
	              INT0 > T0 > INT1 > T1 > SERIAL
***************************************************************************/
   
    IP = 0x00;

/***************************************************************************
          |<----------T1--------->|<----------T0--------->|           TMOD
	  ----------------------------------------------------------     -------
		   GATE     C/T     M1 M0 |GATE     C/T     M1 M0             0X89
****************************************************************************
	   GATE=0,TRX=1             the timer will work
	   GATE=1,TRX=1,INTX=1      the timer will work
	   C/T=1     counter   
	   C/T=0     timer
	   M1M0=00   method 0(13bit)
	   M1M0=01   method 1(16bit)
	   M1M0=10   method 2(8bit autoload)
	   M1M0=11   method 3(two 8bit)
***************************************************************************/

    TMOD = 0x21 ;

/*********************************************************************************************
         TF1         TR1    TF0    TR0     IE1          IT1       IE0    IT0            TCON
    ---------------------------------------------------------------------------       --------  
	 T1 overflow   T1 work             INT1 request  INT1 method                        0X88   
       	1/0       start/stop               1/0        edge/level
*********************************************************************************************/

    TR1 = 0;         //TR1 will work until set TH1 & TL1
    TR0 = 0;

/**************************************************************************
   TODO:if the MCU is 52 serial and you want to use T2,
        you will configure T2MOD ,T2CON yourself.
		make reference to the <regx52.h>.
**************************************************************************/

/******************************************************************************************
        <SM0  SM1>     SM2     REN      TB8      RB8         TI        RI             SCON
 	 -----------------------------------------------------------------------       --------
	     method     multiple  receive  sending  receiving   send     receive          0X98
		 select      select   enable   9th bit  9th bit   interrupt interrupt
*******************************************************************************************
        SM2 just use in the method 2 and 3.
		TI and RI must use software clear.
******************************************************************************************/

    SCON = 0xf0;
    
/**************************************************************************
   TODO:you will configure PCON yourself.
**************************************************************************/

    PCON = 0x00; 

/**************************************************************************
   TODO:please initial THX and TLX.
**************************************************************************/
    TH1 = 0xe6;
    TL1 = 0xe6;                 //the baud rate is 1200;when 12MHz & SMOD=0; 
	
	TR1 = 1;
	EA  = 1;
}

⌨️ 快捷键说明

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