程序我在STC12C5A60S2,运行正常,烧进C8051F300就不行,按照官方的端口配置软件也搞了,还是不行。
#include <stdio.h>
#include "compiler_defs.h"
#include "C8051F300_defs.h"
// Peripheral specific initialization functions,
// Called from the Init_Device() function
void PCA_Init()
{
PCA0MD &= ~0x40;
PCA0MD = 0x00;
}
void Port_IO_Init()
{
P0MDOUT = 0x0F;
XBR2 = 0x40;
}
void Oscillator_Init()
{
OSCICN = 0x00;
}
void Init_Device(void)
{
PCA_Init();
Port_IO_Init();
Oscillator_Init();
}
sbit SCLOCK=P0^0;
sbit DATA=P0^1;
sbit LE=P0^2;
sbit CE=P0^3;
void delay(int);
void main()
{
unsigned long int registe0,registe1,registe2,temp1;
int i;
registe0=0x3000c9; //R Register
registe1=0x4ff904; //C Register
registe2=0x2ee02; //N Register
temp1=0x800000;
CE=1; //Update R Latch, the writing order should be R, C, N
SCLOCK=1;
DATA=0;
LE=0;
for(i=0;i<24;i++)
{
if((temp1®iste0)==0x0)
DATA=0;
else
DATA=1;
SCLOCK=0;
SCLOCK=1;
temp1=temp1>>1;
}
temp1=0x800000;
LE=1;
LE=0;
for(i=0;i<24;i++) //Update C Latch
{
if((temp1®iste1)==0x0)
DATA=0;
else
DATA=1;
SCLOCK=0;
SCLOCK=1;
temp1=temp1>>1;
}
temp1=0x800000;
LE=1;
LE=0;
delay(5000); //interval between programming C and N register needs to be at least 5ms
for(i=0;i<24;i++) //Update N Register
{
if((temp1®iste2)==0x0)
DATA=0;
else
DATA=1;
SCLOCK=0;
SCLOCK=1;
temp1=temp1>>1;
}
temp1=0x800000;
LE=1;
while(1);
}
void delay(int length)
{
while (length >=0)
length--;
} |