原理图设计AD采集转换显示其他电路程序设计#includereg52.h#includeintrins.h#defineuintunsignedint#defineucharunsignedcharsbitled1=P1^0;//数码管位控制sbitled2=P1^1;sbitled3=P1^2;sbitled4=P1^3;sbitsda=P3^4;//24C02数据端口sbitscl=P3^3;//24C02时钟线sbitbeef=P3^5;//蜂鸣器驱动控制sbitrd=P3^7;//A/D转换读信号sbitwr=P3^6;//A/D转换写信号sbits1=P1^4;//按键sbits2=P1^5;sbits3=P1^6;sbits4=P1^7;uintnum,temp,wendu,tiaojie,m;ucharqian,bai,shi,ge,moshi=0,moshi1=0,shangxian=70,xiaxian=20;ucharcodetable[]={0xA0,0xBB,0x62,0x2A,0x39,0x2C,0x24,0xBA,0x20,0x28,0x30,0x25,0xE4,0x23,0x64,0x74};//数码管段码voiddelay(uintxms){uinti,j;for(i=xms;i0;i--)for(j=110;j0;j--);}/********************************************************====================24c02函数=========================*******************************************************/voiddelay1(){;;}voidstart()//开始{sda=1;delay1();scl=1;delay1();sda=0;delay1();}voidstop()//停止{sda=0;delay1();scl=1;delay1();sda=1;delay1();}voidrespons()//应答{uchari;scl=1;delay1();while((sda==1)&(i250))i++;scl=0;delay1();}voidinit()//初始化{sda=1;delay1();scl=1;delay1();}voidwrite_byte(uchardate)//字节写{uchari,temp;temp=date;for(i=0;i8;i++){temp=temp1;scl=0;delay1();sda=CY;delay1();scl=1;delay1();}scl=0;delay1();sda=1;delay1();}ucharread_byte()//字节读{uchari,k;scl=0;delay1();sda=1;delay1();for(i=0;i8;i++){scl=1;delay1();k=(k1)|sda;scl=0;delay1();}returnk;}voidwrite_add(ucharaddress,uchardate)//写入1字节{start();write_byte(0xa0);respons();write_byte(address);respons();write_byte(date);respons();stop();}ucharread_add(ucharaddress)//指定地址读{uchardate;start();write_byte(0xa0);respons();write_byte(address);respons();start();write_byte(0xa1);respons();date=read_byte();stop();returndate;}voidadstart()//启动AD{//cs=0;wr=1;_nop_();wr=0;_nop_();wr=1;}voidadread()//AD读{P2=0xff;rd=1;_nop_();rd=0;_nop_();temp=P2;rd=1;}voidtimer0_init()//定时器T0初始化{TMOD=0x01;TH0=0x3c;TL0=0xb0;ET0=1;//开定时器零中断TR0=1;//启动定时器0EA=1;//开中断}voiddisplay1()//温度显示{wendu=temp*50/9;//温度量程转换qian=wendu/1000;//温度数据分离千位bai=wendu%1000/100;//百位shi=wendu%1000%100/10;//十位ge=wendu%1000%100%10;//个位led1=0;//送位码P0=table[qian];//送段码delay(5);//延时led1=1;//关该位显示led2=0;P0=table[bai];delay(5);led2=1;led3=0;P0=table[shi];delay(5);led3=1;led3=0;P0=0xdf;delay(5);led3=1;//小数点led4=0;P0=table[ge];delay(5);led4=1;}voiddisplay2()//显示温度上限值{uinta,b,c,d;m=tiaojie*50/9;//温度调节a=m/1000;b=m%1000/100;c=m%1000%100/10;d=m%1000%100%10;led1=0;P0=table[a];delay(5);led1=1;P0=0xff;led2=0;P0=table[b];delay(5);led2=1;P0=0xff;led3=0;P0=table[c];delay(5);led3=1;P0=0xff;led3=0;P0=0xdf;delay(5);led3=1;P0=0xff;led4=0;P0=table[d];delay(5);led4=1;P0=0xff;}voidkeyscan()//键扫描{if(s1==0)//功能键1温度上限值设置{delay(5);if(s1==0){while(!s1);moshi++;if(moshi==2){moshi=0;}}}if(s2==0)//功能键2温度下限值设置{delay(5);if(s2==0){while(!s2);moshi1++;if(moshi1==2){moshi1=0;}}}if(moshi==1)//上限值设置{if(s3==0)//加1{delay(5);if(s3==0){while(!s3);shangxian++;//温度上限加1if(shangxian==191){shangxian=190;}write_add(0,shangxian);delay(5);}}if(s4==0)//减1{delay(5);if(s4==0){while(!s4);shangxian--;//温度上限减1if(shangxian==9){shangxian=10;}write_add(0,shangxian);delay(5);}}tiaojie=shangxian;display2();display2();P0=0xff;}if(moshi1==1)//下限值设置{if(s3==0){delay(5);if(s3==0){while(!s3);xiaxian++;//下限值加1if(xiaxian==191){xiaxian=190;}write_add(1,xiaxian);delay(5);}}if(s4==0){delay(5);if(s4==0){while(!s4);xiaxian--;//下限值减1if(xiaxian==3){xiaxian=4;}write_add(1,xiaxian);delay(5);}}tiaojie=xiaxian;display2();P0=0xff;}}voidmain(){timer0_init();//定时器T0初始化init();//系统初始化shangxian=read_add(0);//读温度设置上限值xiaxian=read_add(1);//读温度设置下限值while(1){if(moshi==0&&moshi1==0)//没有温度上下限值设置{display1();//显示测试温度keyscan();//键扫描}keyscan();//键扫描if(moshi==1||moshi1==1)//温度上下限设置{keyscan();//键扫描}if(tempshangxian||tempxiaxian)//温度大于上限值或下限值报警{beef=0;}elsebeef=1;//关闭报警}}voidtimer0()interrupt1{TH0=0x3c;//重赋初值TL0=0xb0;num++;//中断次数加1if(num==1){adstart();}//AD启动if(num==13){adread();num=0;}//读AD值}