直接上初始代码吧,替换你的相关部分代码
/////////////////////////////////////
// Generated Initialization File //
/////////////////////////////////////
#include "C8051F310.h"
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void PCA_Init()
{
PCA0MD &= ~0x40;
PCA0MD = 0x00;
}
void Port_IO_Init()
{
// P0.0 - Unassigned, Open-Drain, Digital
// P0.1 - Unassigned, Open-Drain, Digital
// P0.2 - Skipped, Open-Drain, Analog
// P0.3 - Skipped, Open-Drain, Analog
// P0.4 - Unassigned, Open-Drain, Digital
// P0.5 - Unassigned, Open-Drain, Digital
// P0.6 - Unassigned, Open-Drain, Digital
// P0.7 - Unassigned, Open-Drain, Digital
// P1.0 - Unassigned, Open-Drain, Digital
// P1.1 - Unassigned, Open-Drain, Digital
// P1.2 - Unassigned, Open-Drain, Digital
// P1.3 - Unassigned, Open-Drain, Digital
// P1.4 - Unassigned, Open-Drain, Digital
// P1.5 - Unassigned, Open-Drain, Digital
// P1.6 - Unassigned, Open-Drain, Digital
// P1.7 - Unassigned, Open-Drain, Digital
// P2.0 - Unassigned, Open-Drain, Digital
// P2.1 - Unassigned, Open-Drain, Digital
// P2.2 - Unassigned, Open-Drain, Digital
// P2.3 - Unassigned, Open-Drain, Digital
P0MDIN = 0xF3;
P0SKIP = 0x0C;
}
void Oscillator_Init()
{
int i = 0;
OSCXCN = 0x67;
for (i = 0; i < 3000; i++); // Wait 1ms for initialization
while ((OSCXCN & 0x80) == 0);
CLKSEL = 0x01;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
PCA_Init();
Port_IO_Init();
Oscillator_Init();
} |