程序如下
#define uchar unsigned char
#define uint unsigned int
#include <reg52.h>
#include <stdio.h>
#include <absacc.h>
sbit fpga_nconfig=P1^2;
sbit fpga_dclk=P1^4;
sbit fpga_data=P1^0;
sbit fpga_nstatus=P1^1;
sbit fpga_confdone=P1^3;
void delay_ms(uint x);
void fpga_updata(uint Address);
uchar code fpgacode[]={
};
void delay_ms(uint x)
{uint i,j;
for(j=0;j <=x;j++)
{for(i=0;i <536;i++);}
}
void fpga_updata() //配置FPGA子程序
{
uchar temp,temp1,i,j;
uint Address,k;
start:
fpga_dclk=0;
fpga_confdone=1;
fpga_nconfig=0;
fpga_nstatus=1;
fpga_data=0;
fpga_dclk=0;
for(k=0;k <30000;k++);
fpga_nconfig=0;
for(k=0;k <30000;k++);
fpga_nconfig=1;
Address=0;
while(1)
{
temp=fpgacode[Address];//取出一个字节的数据(8位)
Address++;
while(Address> 14750) {
for(j=0;j <10;j++) {
fpga_dclk=1;
fpga_dclk=0;
}
// for(j=0;j <60000;j++);
// for(j=0;j <60000;j++);
// for(j=0;j <60000;j++);
// for(j=0;j <60000;j++);
// for(j=0;j <60000;j++);
for(k=0;k <60000;k++);
for(k=0;k <60000;k++);
for(k=0;k <60000;k++);
goto start ;
};
for(i=0;i <8;i++)//送出8位数
{
//temp1=temp & 0x01;
fpga_data=(bit) (temp & 0x01);
temp=temp> > 1;
for(j=0;j <50;j++);
// fpga_dclk=0;//DCLK来一个低脉冲
fpga_dclk=1;
//for(j=0;j <1;j++);
fpga_dclk=0;//DCLK来一个低脉冲
//for(j=0;j <1;j++);
// }
if(!fpga_nstatus) //检测nStatus状态,如为低,则配置出错,延时后重新配置
{
while(1);
}
}
if(fpga_confdone)//检测到CONFIGDONE为高,则配置成功,再送出10个DCLK
{
for(j=0;j <10;j++) {
fpga_dclk=1;
fpga_dclk=0;
}
while(1);
}
}
return;
}
main()
{
fpga_updata();
while(1);
}