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

📄 initial.#1

📁 本程序运行于C8051F330
💻 #1
字号:
#include "C8051F330.H"
#include "IR_Rx_Tx.h"


//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
//
// Configure the Crossbar and GPIO ports.
//
// P0.0 - SMBus SDA
// P0.1 - SMBus SCL


void PORT_Init (void)
{
   //P0SKIP  |= 0x01;                    // Skip P0.0 for external VREF
   //P0MDIN  |= 0x01;                    // Configure P0.0 as analog input.
   //P0MDOUT |= 0x10;                    // enable UTX as push-pull output
  // P1MDOUT |= 0x08;                    // enable LED as push-pull output
   //XBR0    = 0x05;                     // Enable UART on P0.4(TX) and P0.5(RX)and sclP01 sdaP00                     
   //XBR1    = 0x40;                     // Enable crossbar and weak pull-ups
   P0MDIN      = 0xFF;
	//P1MDIN      = 0xFF;
   P0MDOUT     = 0x00;
    //P1MDOUT     = 0xFF;
   XBR0    = 0x04;                     // Enable IIC on P0.0(SDA) and P0.1(SCL)             
   XBR1    = 0x40;                     // Enable crossbar and weak pull-ups

   //P0 = 0xFF;
   
}

//-----------------------------------------------------------------------------
// SYSCLK_Init
//-----------------------------------------------------------------------------
//
// This routine initializes the system clock to use the internal oscillator
// at its maximum frequency.
// Also enables the Missing Clock Detector.
//

void SYSCLK_Init (void)
{
   OSCICN |= 0x03;                     // Configure internal oscillator for
                                       // its maximum frequency
   RSTSRC  = 0x04;                     // Enable missing clock detector

}




void Timer3_Init (int counts)
{
   TMR3CN = 0x00;                      // STOP Timer2; Clear TF2H and TF2L;
                                       // disable low-byte interrupt; disable
                                       // split mode; select internal timebase
   CKCON |= 0x40;                      // Timer2 uses SYSCLK as its timebase

   TMR3RL  = -counts;                  // Init reload values
   TMR3    = TMR3RL;                   // Init Timer2 with reload value
   EIE1 |=0x80 ;                            // disable Timer2 interrupts
   TMR3CN |=0x04;                            // start Timer2

}





void SMBus_Init(void)
{
   SMB0CF = 0x01;
   SMB0CF |= 0x80;                  //Enable slave SMBus and EXTHOLD

      SMB0CN &= ~0x40;                       // Reset communication
      SMB0CN |= 0x40;

      //SMB0CF &= ~0x40;                       // Reset communication
      //SMB0CF |= 0x40;

   EIE1   |= 0x01;                  //Enable SMBus interrupt   
}





void Interrupts_Init()
{
     EA=1;
     //EX0=1;
}

⌨️ 快捷键说明

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