下面这是官网给的控制一个芯片的参考程序,就是把数据通过单片机发送到芯片中的三个寄存器当中,官网参考程序用的是ADUC841单片机,我想改成C8051F300这个封装很小的单片机,想用P0^0,P0^1,P0^2,P0^3四个引脚,数字交叉开关和端口配置什么的,我试了很多次,实在没办法了,来这里求教了!学生党表示需要学习求教的东西很多,希望大家多多帮助,真心谢谢了!
#include <stdio.h>
#include <ADuC841.h>
sbit DATA=P3^3;
sbit SCLOCK=P3^4;
sbit LATCH=P3^5;
sbit CE=P3^7;
void delay(int);
void main()
{
unsigned long int registe0,registe1,registe2,temp1;
int i;
registe0=0x300029; //R Register
registe1=0x0ff100; //C Latch
registe2=0x007802; //N Register
temp1=0x800000;
CE=1; //Update R Latch the order of writing the registers should be R,C,N
SCLOCK=1;
DATA=0;
LATCH=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;
LATCH=1;
LATCH=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;
LATCH=1;
LATCH=0;
delay(5000); //interval between programming C and N register needs to be at least 15ms
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;
LATCH=1;
while(1);
}
void delay(int length)
{
while (length >=0)
length--;
} |