您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 51单片机光强检测(含AD转换)仿真
单片机光强检测系统完整程序:#includereg52.hsfr16DPTR=0X82;sbitP27=P2^7;sbitP26=P2^6;sbitP07=P0^7;sbitcs=P1^3;sbitdout=P1^4;sbitadin=P1^5;sbitclock=P1^6;sbiteoc=P1^7;unsignedchara[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};unsignedintr,s;voiddelay_us(unsignedintz)//小延时{while(z--);}voiddelay_ms(unsignedintms)//1毫秒延时{intx,y;for(x=ms;x0;x--)for(y=120;y0;y--);}voiddisplay(){r=DPTR*50;r=r/1023;r=r/10;P27=0;P26=1;P0=a[r];delay_ms(2);P07=0;//小数点s=DPTR*50;s=s/1023;s=s%10;P26=0;P27=1;P0=a[s];delay_ms(2);}/*************A/D转换****************/voidad1543addr(unsignedcharaddr){unsignedintdateout=0;unsignedchark,i,j;clock=0;cs=0;for(i=0;i4;i++){adin=(bit)(addr&0x08);clock=1;clock=0;addr=1;//=左移赋值运算符}for(j=0;j6;j++){clock=1;clock=0;}cs=1;delay_us(5);cs=0;delay_us(5);for(k=0;k10;k++){dout=1;clock=1;dateout=1;if(dout)dateout+=1;clock=0;}DPTR=dateout;//return(dateout);}/*************************************/voidmain(){ad1543addr(0x02);display();}
本文标题:51单片机光强检测(含AD转换)仿真
链接地址:https://www.777doc.com/doc-5032125 .html