#includereg51.hsbitCLK=P1^1;sbitSDA=P1^2;sbitA=P2^0;sbitM=P2^1;sbitC=P2^2;unsignedcharnum[10]={0X3f,0X06,0X5b,0X4f,0X66,0X6d,0X7d,0X07,0X7f,0X6f};//-------------IIC--------------------voidIIC_Delay(){;;}voidstart(){SDA=1;IIC_Delay();CLK=1;IIC_Delay();SDA=0;IIC_Delay();}voidstop(){SDA=0;IIC_Delay();CLK=1;IIC_Delay();SDA=1;IIC_Delay();}voidanswer(){CLK=1;IIC_Delay();while(SDA==1);CLK=0;IIC_Delay();}voidwrite_byte(unsignedchardat){unsignedchari;for(i=0;i8;i++){dat=dat1;CLK=0;IIC_Delay();SDA=CY;IIC_Delay();CLK=1;IIC_Delay();}CLK=0;IIC_Delay();SDA=1;IIC_Delay();}unsignedcharread_byte(){unsignedchari,dat;CLK=0;IIC_Delay();SDA=1;IIC_Delay();for(i=0;i8;i++){CLK=1;IIC_Delay();dat=dat1;if(SDA)dat=dat|0x01;CLK=0;IIC_Delay();}returndat;}//-------------IICA/DD/A-----------------------voidDA_trans(unsignedchardat){start();write_byte(0x90);answer();write_byte(0x40);answer();write_byte(dat);answer();stop();}unsignedcharAD_trans(){unsignedchardat;start();write_byte(0x90);answer();write_byte(0x02);answer();start();write_byte(0x91);answer();dat=read_byte();stop();returndat;}//-----------------------------------------------voiddelay(unsignedcharXms){unsignedinti,j;for(i=0;iXms;i++)for(j=0;j114;j++);}//------------------------------------------------voidweixuan(charx,chary,charz){A=x;M=y;C=z;}voidDisplay(unsignedchardat){weixuan(0,0,0);P0=num[dat/100];delay(5);weixuan(1,0,0);P0=num[(dat%100)/10];delay(5);weixuan(0,1,0);P0=num[dat%10];delay(5);}//------------------------------------------------main(){unsignedchardat;while(1){dat=AD_trans();Display(dat);}}