全部博文(354)
分类: 嵌入式
2010-08-25 21:59:36
printf("Pull down BCK data.2\n");
CLR_BCK(data);
getch();
printf("Pull up BCK data.2\n");
SET_BCK(data);
getch();
printf("Pull down DATA data.3\n");
CLR_DATA(data);
getch();
printf("Pull up DATA data.3\n");
SET_DATA(data);
getch();
}
// Note: the size of buffer to send must be dword multiple
// size is the number of bytes to send
void short_delay(int n)
{
int i;
for(i=0;i {int temp =0;}
}
int send_spi_data(unsigned char *buffer, unsigned long size)
{
unsigned char buff[1024];
unsigned char *buf=buff;
unsigned char data;
int i,j,k;
data =0;
if((size%4)!=0) return FALSE;
memcpy(buff,buffer,size);
do{
SET_WCK(data);
for(k=0;k<2;k++){
for(j=0;j<2;j++){
printf(".");
for(i=0;i<8;i++){
if((*buf)&0x80){
SET_DATA(data);
}else{
CLR_DATA(data);
}
short_delay(1);
// delay(1);
SET_BCK(data);
short_delay(1);
// delay(1);
CLR_BCK(data);
short_delay(1);
// delay(1);
*buf<<=1;
}
buf++;
size--;
}
// buf++;
// size--;
CLR_WCK(data);
}
SET_WCK(data);
}while(size>0);
return TRUE;
}
/*
void main()
{
int i;
unsigned char tmpdata[4];
tmpdata[0] = 0x34;
tmpdata[1] = 0x12;
tmpdata[2] = 0x56;
tmpdata[3] = 0x78;
// for(i=0;i<500;i++)
for(i=0;i<50;i++)
{
send_spi_data(tmpdata,4);
}
// test_comm();
}
*/