int search(char (*p)[20],char *str);
//{rp是一个指针数组,每个元素是指向20个字符元素。sgliu 即可以用于二维数组 */
void main() { char str[5][20]={“avddx”,“12658”,“sewxx”,“ssxer”,“abcde”},
s_str[20];
int line;
printf(“Please input the string you want to search:”);
gets(s_str);
line=search(str,s_str);
//将二维数组名作为参数传递进去
printf (“line = %d\n”, line); }
int search(char (p)[20],char str)
{ int i,j=0;
for(i=0;i<5;i++)
if(strcmp((const char)(p+i),str)==0//判断 j++; return j; }
void Datapros(uint num)
{
disp[0]=num/100+0x30; disp[1]=num%100/10+0x30; disp[2]=num%100%10+0x30; Disp_shuzi(100,100,disp[0],Red); Disp_shuzi(108,100,disp[1],Red); Disp_shuzi(116,100,disp[2],Red);
}
main()
{
while(1)
{ _24c64WriteByte(1,68); num=_24c64ReadByte(1);
Datapros(num);
}
}
/******************************************
AT24C64C语言程序
copyright@lance
******************************************/
sbit ISCL = P6^4;
sbit ISDA = P6^3;
void delay1ms(Uint n)
{
Uint i,j;
for(i=n;i>0;i–)
{
for(j=750;j>0;j–)
{
}
}
}
/*****************************************
I2c Wait
Wait for some time to get proper I2C timing
*/
void I2cWait(void)
{
// unsigned int i=10; //24C64
unsigned int i=5;//24C256
while(i–);
}
/
i2c start
condition SDA 1-0 while SCL=1
******************************************/
void I2cStart(void)
{
ISDA=1;
ISCL=1;
I2cWait();
ISDA=0;
I2cWait();
ISCL=0;
I2cWait();
}
/*****************************************
I2c sotp
condition SDA=0-1 while SCL=1
******************************************/
void I2cStop(void)
{
ISDA=0;
I2cWait();
ISCL=1;
I2cWait();
ISDA=1;
I2cWait();
}
/*****************************************
I2c Init
Initialize I2C interface
Release I2c BUS
****************************************
void I2cInit(void)
{
ISDA=1;
ISCL=1;
I2cWait();
}
/*****************************************
I2c SentByte
master transfer data to slave and return acknowledge bit
don’t include<intrins.h>
******************************************/
bit I2cSentByte(unsigned char bytedata)
{
unsigned char i;
bit ack;
for(i=0;i<8;i++)
{
if(bytedata & 0x80)
ISDA=1;
else
ISDA=0;
bytedata<<=1;
I2cWait();
ISCL=1;
I2cWait();
ISCL=0;
I2cWait();
}
ISDA=1;
I2cWait();
ISCL=1;
I2cWait();
ack=ISDA;
ISCL=0;
I2cWait();
return ack;
}
/*****************************************
I2c ReceiveByte
slave trransfer data to master
******************************************/
unsigned char I2cReceiveByte(void)
{
unsigned char i;
unsigned char bytedata=0;
ISCL=0;
I2cWait();
for(i=0;i<8;i++)
{
ISCL=1;
I2cWait();
bytedata=bytedata<<1;
if(ISDA==1)
{
bytedata = bytedata|0x01;
}
I2cWait();
ISCL=0;
I2cWait();
}
return bytedata;
}
/*****************************************
I2c SendAcknowledge
Master send acknowledge bit to slave
acknowledge=“0”,non-acknowledge=“1”
******************************************/
void SendAcknowledge(bit ack)
{
ISDA=ack;
ISCL=1;
I2cWait();
ISCL=0;
}
/*****************************************
24c64 WriteByte
addr:0-8192
value:数据
******************************************/
void _24c64WriteByte(unsigned int addr,unsigned char value)
{
I2cStart();
I2cSentByte(0xA0);
I2cSentByte(addr>>8); //送高位地址
I2cSentByte(addr&0x00ff); //送低位地址
I2cSentByte(value);
I2cStop();
delay1ms(15);
}
/*****************************************
24c64 WriteMulti
page:0-255
count:要写入的数个数
******************************************/
void _24c64WriteMulti(unsigned int page,unsigned char count,unsigned char *SenBuf)
{
unsigned char i;
unsigned int addr=page*32;
I2cStart();
I2cSentByte(0xa0);
I2cSentByte(addr>>8); //送高位地址
I2cSentByte(addr&0x00ff); //送低位地址
for(i=0;i<count;i++)
{
I2cSentByte(SenBuf[i]);
}
I2cStop();
delay1ms(15);
}
/*****************************************
24c64 ReadByte
addr:0-8192
******************************************/
unsigned char _24c64ReadByte(unsigned int addr)
{
unsigned char temp;
I2cStart();
I2cSentByte(0xa0);
I2cSentByte(addr>>8); //送高位地址
I2cSentByte(addr&0x00ff); //送低位地址
I2cStart();
I2cSentByte(0xa1);
temp=I2cReceiveByte();
SendAcknowledge(1);
I2cStop();
return temp;
}
/*****************************************
24c64 ReadMulti
page:0-256,count0-32
count:要读出的数的个数
******************************************/
void _24c64ReadMulti(unsigned int page,unsigned char count,unsigned char RedBuf)
{ unsigned int addr=page32;
unsigned char i;
for(i=0;i<count;i++)
{ RedBuf[i]=_24c64ReadByte(addr); addr++; }
SendAcknowledge(1); I2cStop();
}