您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > PCF8591实现AD转换程序
PCF8591实现AD转换程序#includereg52.hsbitSCL=P2^1;sbitSDA=P2^0;sbitdula=P2^6;sbitwela=P2^7;unsignedcharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};voiddelay(){inti=4;while(i--);}voiddelay_s(){unsignedchara,b;for(b=3;b0;b--)for(a=100;a0;a--);}voiddisplay(intdd){dula=1;P0=table[dd/100];dula=0;delay_s();P0=0xff;wela=1;P0=0xfe;wela=0;delay_s();wela=1;P0=0xff;wela=0;dula=1;P0=0x80;dula=0;delay_s();P0=0xff;wela=1;P0=0xfe;wela=0;delay_s();wela=1;P0=0xff;wela=0;dula=1;P0=table[dd%100/10];dula=0;delay_s();P0=0xff;wela=1;P0=0xfd;wela=0;delay_s();wela=1;P0=0xff;wela=0;dula=1;P0=table[dd%10];dula=0;delay_s();P0=0xff;wela=1;P0=0xfb;wela=0;delay_s();wela=1;P0=0xff;wela=0;}//写iic总线的几个重要函数voidinitIIC(){SCL=1;delay();SDA=1;delay();}voidstart(){SCL=1;delay();SDA=1;delay();SDA=0;delay();}voidrespons(){unsignedchari;SCL=1;delay();while((SDA==1)&&i255)i++;SCL=0;delay();}voidstop(){SCL=1;delay();SDA=0;delay();SDA=1;delay();}voidwritebyte(unsignedchardate){unsignedchartemp,i;temp=date;for(i=0;i8;i++){temp=temp1;SCL=0;delay();SDA=CY;delay();SCL=1;delay();}SCL=0;delay();SDA=1;delay();}unsignedcharreadbyte(){unsignedchari,k;SCL=0;delay();SDA=1;for(i=0;i9;i++){SCL=1;delay();k=(k1)|SDA;SCL=0;delay();}delay();returnk;}//发送数据给芯片voidsend(unsignedcharaddress,unsignedchardate){start();writebyte(0x90);respons();writebyte(address);respons();writebyte(date);respons();stop();}//从芯片独处数据unsignedcharread(unsignedcharaddress){unsignedchartemp;start();writebyte(0x90);respons();writebyte(address);respons();start();writebyte(0x91);temp=readbyte();returntemp;}voidmain(){inttemp;unsignedcharpp;initIIC();while(1){temp=read(0x43);temp=temp*1.9767;display(temp);}}
本文标题:PCF8591实现AD转换程序
链接地址:https://www.777doc.com/doc-2341677 .html