www.pudn.com > spi.rar > spi.c


#include  
#include  
#include  
#include  
#include  
 
#define LPT_PORT  0x378 
#define CLR_WCK(X)  {X=X&(~(1<<0)); outportb(LPT_PORT,X); }  // data.0 
#define SET_WCK(X)  {X=X | (1<<0) ; outportb(LPT_PORT,X); } 
#define CLR_BCK(X)  {X=X&(~(1<<2)); outportb(LPT_PORT,X); }  // data.2 
#define SET_BCK(X)  {X=X | (1<<2) ; outportb(LPT_PORT,X); } 
#define CLR_DATA(X) {X=X&(~(1<<3)); outportb(LPT_PORT,X); }  // data.3 
#define SET_DATA(X) {X=X | (1<<3) ; outportb(LPT_PORT,X); } 
#define FALSE 0 
#define TRUE  1 
void test_comm() 
{ 
unsigned char data ; 
data = 0; 
printf("Please press enter to begin send data\n"); 
getch(); 
printf("Pull down WCK data.0\n"); 
CLR_WCK(data); 
getch(); 
printf("Pull up WCK data.0\n"); 
SET_WCK(data); 
getch(); 
 
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(); 
} 
// Ë«×Ö½Ú 
// ËÍ×Ö½ÚÊý 
void short_delay(int n) 
{ 
int i; 
for(i=0;i0); 
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<50;i++) 
{ 
send_spi_data(tmpdata,4); 
} 
}