adc0834

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

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

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

资源描述

#includereg52.h#includeintrins.h#defineucharunsignedchar//ºê¶¨Òå#defineuintunsignedintsbitcs0=P2^0;//I/0¿Úsbitcs1=P2^1;sbitcs2=P2^2;sbitcs3=P2^3;sbitcs4=P2^4;sbitrow0=P2^5;sbitrow1=P2^6;sbitrow2=P2^7;sbitsw1=P1^6;sbitsw2=P1^7;sbitSDO=P1^0;sbitADCS=P1^1;sbitSDI=P1^2;sbitCLK=P1^3;ucharTTAB[10]={0x03,0x9F,0x25,0x0D,0x99,0x49,0x41,0x1F,0x01,0x09};//´®¿ÚÏÔʾ¶ÎÂë0`9ucharsta,fsw1,fsw2,count=0,num1,num2,num3,num4,num5,shu,adc,hex;/*º¯ÊýµÄÉùÃ÷*/voidinit();ucharADC0834(uchartds);voidsz(uchartds);voidmn(uchartds);voiddisplay();//ÊýÂ붯̬ÏÔʾvoidkeyscan1();voidckxs(ucharr);voidwork0();voidwork1();voidwork2();voidwork3();voidwork4();voidmain(){init();while(1){if(TF0==1)//ÅжÏ5msÊÇ·ñµ½ÁË{TF0=0;TH0=(65536-5000)/256;//ÖØи³¼ÆÊý³õÖµTL0=(65536-5000)%256;count++;keyscan1();//¶ÀÁ¢°´¼üɨÃèdisplay();//¶¯Ì¬É¨Ãèswitch(sta)//¸ù¾Ýstaɢת{case0:work0();break;case1:work1();break;case2:work2();break;case3:work3();break;case4:work4();break;default:break;}}}}voiddisplay(){uchartable[17]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};//0~fµÄ¶ÎÂë±íucharttable[11]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0xff};//0~9´øСÊýµã¶ÎÂë±íucharled[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};P2=0xff;switch(shu){case0:P0=table[num1];cs0=0;shu++;break;case1:P0=table[num2];cs1=0;shu++;break;case2:P0=table[num3];cs2=0;shu++;break;case3:P0=ttable[num4];cs3=0;shu++;break;case4:P0=led[num5];cs4=0;shu=0;break;default:break;}}voidinit(){TMOD=0x01;TH0=(65536-5000)/256;//¸³¼ÆÊý³õÖµTL0=(65536-5000)%256;TR0=1;sta=0;}//=========================/*******ADC0834ת»»******///Èë¿Ú²ÎÊý£ºÍ¨µÀÑ¡Ôñ£»³ö¿Ú²ÎÊý£º×ª»»Êä³ö//=========================ucharADC0834(uchartds){uchari,advalue=0;ADCS=0;for(i=0;i5;i++){CLK=0;SDI=tds&0x80;CLK=1;tds=1;}SDO=1;for(i=0;i8;i++){CLK=0;CLK=1;advalue=(advalue1)|SDO;}for(i=0;i8;i++){CLK=0;CLK=1;}ADCS=1;returnadvalue;}//===============================/*******Êý×ÖÁ¿Êä³ö************///===============================voidsz(uchartds){ucharhex;hex=ADC0834(tds);num4=10;num3=hex/100;num2=hex/10%10;num1=hex%10;}//===============================/*******Ä£ÄâÁ¿Êä³ö************///===============================voidmn(uchartds){uinthex;staticintnum;hex=ADC0834(tds);num=hex*5000./255;num4=num/1000;num3=num%1000/100;num2=num%1000%100/10;num1=num%10;}voidwork0(){uintss=0;ckxs(0);num4=10;num3=10;num2=13;num1=12;if(fsw1==1){fsw1=0;num4=0;num3=0;num2=0;num1=0;sta=1;}}voidwork1(){ckxs(1);if(count==200){count=0;num1++;if(num1==10){num1=0;num2+=1;if(num2==6){num2=0;num3+=1;if(num3==10){num2=0;num4+=1;if(num4==6){sta=2;}}}}}if(fsw1==1){fsw1=0;sta=2;}if(fsw2==1){fsw2=0;sta=3;}}voidwork2(){staticucharaa=0;ckxs(2);if(fsw1==1)//Ñ¡¹¤×÷Ϊµ¥¶Ë»ò²î·Ö{fsw1=0;aa++;if(aa==4){aa=0;}}switch(aa){//Êý×ÖÁ¿Êä³öcase0:sz(0xc0);num5=0;break;//µ¥¶Ë·½Ê½CH0case1:sz(0xe0);num5=1;break;//µ¥¶Ë·½Ê½CH1case2:sz(0xd0);num5=2;break;//µ¥¶Ë·½Ê½CH2case3:sz(0x80);num5=3;break;//²î·Ö·½Ê½CH0CH1default:break;}if(fsw2==1){fsw2=0;sta=3;}}voidwork3(){staticucharbb=0;ckxs(3);if(fsw1==1)//Ñ¡¹¤×÷Ϊµ¥¶Ë»ò²î·Ö{fsw1=0;bb++;if(bb==4){bb=0;}}switch(bb){//Ä£ÄâÁ¿Êä³öcase0:mn(0xc0);num5=0;break;//µ¥¶Ë·½Ê½CH0case1:mn(0xe0);num5=1;break;//µ¥¶Ë·½Ê½CH1case2:mn(0xd0);num5=2;break;//µ¥¶Ë·½Ê½CH2case3:mn(0x80);num5=3;break;//²î·Ö·½Ê½CH0CH1default:break;}if(fsw2==1){fsw2=0;sta=4;}}voidwork4(){ckxs(4);sz(0xd0);if(!adc--){adc=ADC0834(0xd0);num5++;if(num5==7){num5=0;}}if(fsw2==1){fsw2=0;sta=1;}}/*´®¿Ú·½Ê½ÏÔʾ*/voidckxs(ucharr){ucharm;SCON=0x00;m=TTAB[r];SBUF=m;}voidkeyscan1()//¶ÀÁ¢¼üÅÌ{staticucharcnt,sw1flag,sw2flag;P1=0xc0;_nop_();if(sw1==0||sw2==0){cnt++;if(cnt==4)//ÑÓʱ20msµ½£¿{cnt=0;if(sw1==0)sw1flag=1;if(sw2==0)sw2flag=1;}}elseif(sw1!=0&&sw2!=0)//ͬʱ·Å¿ª{cnt=0;if(sw1flag==1){sw1flag=0;fsw1=1;}if(sw2flag==1){sw2flag=0;fsw2=1;}}}

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

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

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

×
保存成功