www.pudn.com > LPC2148CH375.rar > gpio.c


#include "config.h" 
uint32 u; 
void delay2us(void) 
{ 
	uint16 i=9; 
	while(i--); 
} 
 
void delay1us(void) 
{ 
	uint16 i=5; 
	while(i--); 
} 
 
void	mDelay100mS(void ) 
{ 
	uint16	i=5000; 
	while(i--) 
	delay2us();	 
} 
 
 
 
 
void gpio_init(void) 
{ 
	SCS     = 0; 
	PINSEL0 = 0x00000000; 
	PINSEL1 = 0x00000000; 
	PINSEL2 = 0x00000004; 
	IODIR0  = (1<<25) | (1<<28) | (1<<29) | (0x80000000) ; //cs rd wr a0 set to out	 
	IOSET0  = 1<<28 | 1<<29; 
	 
} 
 
 
void xWriteCH375Cmd( uint8 mCmd ) 
{  
	//uint32 i=1; 
	IODIR0 = (1<<25) | (1<<28) | (1<<29) | (0x80000000)  | 0x00ff0000; 
	delay2us();	 
	 
	IOPIN0 = (IOPIN0 & (~(1<<25 | 0x80000000))) | 0x80000000; 
	 
	IOPIN0 = (IOPIN0 & (~(1<<28 | 0x80000000))) | 0x80000000; //WRÖÃ0 
	 
	IOPIN0 = (IOPIN0 & 0x7f00ffff) | ((uint32)mCmd<<16) | 0x80000000; //дXD0~7 
 
	IOPIN0 = IOPIN0 | (1<<28) | 0x80000000;	  //WRÖÃ1 
	 
	IOSET0 = 1<<25; 
	 
	delay2us();	 
	 
 
} 
 
void xWriteCH375Data( uint8 mData )  
{ 
	//uint32 i=1;	 
	 
	IODIR0 = (1<<25) | (1<<28) | (1<<29) | (0x80000000)  | 0x00ff0000; 
	 
	IOCLR0 = 0x80000000 | 1<<25;               //A0ÖÃ0,CSÖÃ0 
	 
	IOPIN0 = IOPIN0 & (~(1<<28)); //WRÖÃ0 
	 
	IOPIN0 = (IOPIN0 & 0xff00ffff) | ((uint32)mData<<16); //дXD0~7 
	 
	IOPIN0 = IOPIN0 | (1<<28);	  //WRÖÃ1 
	 
	IOSET0 = 1<<25; 
	 
	delay1us();	 
	 
 
} 
 
uint8 xReadCH375Data( void )  
{ 
	uint8 xd; 
	IODIR0 =( (1<<25) | (1<<28) | (1<<29) | (0x80000000) ) & 0xff00ffff; 
	 
	IOCLR0 = 0x80000000 | 1<<25;                 //A0ÖÃ0,CSÖÃ0 
	 
	IOPIN0 = IOPIN0 & (~(1<<29)); //RDÖÃ0 
	 
	IOPIN0 = IOPIN0 | (1<<29);	  //RDÖÃ1 
	 
	xd     = (IOPIN0 & 0x00ff0000)>>16; //¶ÁÈ¡XD0~7 
	 
	IOSET0 = 1<<25; 
	 
	delay1us();	 
	return xd;	  
}