#include sbit ADDAT=P1^6; sbit ADCS=P1^4; unsigned char ADTEMP; int t1,t2,t3; unsigned char TABNU[16]={0xc0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8, 0x80,0x90,0x88,0x83,0xC6,0x0A1,0x86,0x8E }; void ADCONV(void); void TUNBCD(void); void ADPLAY(void); void DELAY2MS(void); void main() { ADTEMP=0x00; P0=0XFF; P2=0XFF; while(1) { int i; ADCONV(); for(i=10;i>0;i--) { TUNBCD(); ADPLAY(); } } } void ADCONV(void) { int i; ADCS=1; ADCLK=0; ADCS=0; ADDAT=1; ADCLK=1; ADDAT=0; ADCLK=0; ADDAT=1; ADCLK=1; ADDAT=0; ADCLK=0; ADDAT=0; ADCLK=1; ADDAT=1; ADCLK=0; _nop_(); _nop_(); ADCLK=1; for(i=8;i>0;i--) { ADCLK=0; ADTEMP|=ADDAT; ADTEMP<<=1; if(i==7) ADTEMP|=ADDAT; ADCLK=1; } ADCS=1; } void TUNBCD(void) {int t; t=ADTEMP*1.0/255*500; t1=t%10; t2=(t/10)%10 ; t3=(t/100%10); } void ADPLAY(void) { P2=0xff; P0=TABNU[t1]; P2=0xfe; DELAY2MS(); DELAY2MS(); DELAY2MS(); P0=TABNU[t2]; P2=0xfd; DELAY2MS(); DELAY2MS(); DELAY2MS(); P0=TABNU[t3]&0x7f; P2=0xfb; DELAY2MS(); DELAY2MS(); DELAY2MS(); } void DELAY2MS(void) { int k; for(k=0;k<500;k++); } 的AD电压表程序 因篇幅问题不能全部显示,请点此查看更多更全内容