//LPC2214 //I2C接口速度在500HZ-200KHZ void CH452_Write(unsigned short command) //写命令 { I2CONCLR = 0x2C; I2CONSET = 0x60; //I2C HOST START while(I2STAT==0XF8); //WAIT START I2DAT=((unsigned char)(command>>7)&0x3E)|0x60; //LOAD ADDR I2CONCLR=0X28; //CLR SI while(I2STAT==0XF8); //WAIT I2DAT=(unsigned char)command; //LOAD DAT I2CONCLR=0X28; //CLR SI while(I2STAT==0XF8); //WAIT I2CONSET|=0X10; //SET STO while(I2STAT==0XF8); }
unsigned char CH452_Read( void ) //读取按键 { unsigned char k; I2CONCLR = 0x2C; I2CONSET = 0x60; //I2C HOST START while(I2STAT==0XF8); //WAIT START I2DAT=0X6F; //IF ADDR=0 I2DAT=0X4F; I2CONCLR=0X28; //CLR SI while(I2STAT==0XF8); //WAIT I2CONCLR = 0x2c; //RECV while(I2STAT==0XF8); //WAIT k=I2DAT; I2CONSET|=0X10; //SET STO while(I2STAT==0XF8); return(k); } void I2C_Init(unsigned long fi2c) { if(fi2c>200000) fi2c = 200000;
PINSEL0 = (PINSEL0&0xFFFFFF0F) | 0x50; I2SCLH = (Fpclk/fi2c + 1) / 2; I2SCLL = (Fpclk/fi2c) / 2; I2CONCLR = 0x2C; I2CONSET = 0x40; }