📄 initial.c
字号:
#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)
{
P0MDIN = 0xFF;
P0MDOUT = 0x00;
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;
EIE1 |= 0x01; //Enable SMBus interrupt
}
void Interrupts_Init()
{
EA=1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -