PCF8591-单片机C语言程序--ADDA装换

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#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);}}

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功