信号源参数设置(U2)
(程序)
- #include<reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbitoe=P2^0;
- sbiteoc=P2^1;
- sbitst=P2^2;
- sbitale=P2^6;
- sbitrs=P2^4;
-
- sbitre=P2^5;
- uchar tab[]={0,'.',0,0};
- uintgetdata;
- voiddelay(uint x)
- { uint a,b;
- for(a=x;a>0;a--)
- for(b=110;b>0;b--); }
- void wzhiling(uchar zhiling)
- {
- rs=0;
- re=0;
- delay(1);
- P0=zhiling;
- delay(2);
- re=1;
- delay(2);
- re=0;
- }
- void wshuju(uchar shuju)
- { rs=1;
- re=0;
- delay(2);
- P0=shuju;
- delay(2);
- re=1;
- delay(2);
- re=0;
- }
- void INIT()
- {
- wzhiling(0x38);
- delay(1);
- wzhiling(0x0c);
- delay(1);
- wzhiling(0x06);
- delay(1);
- wzhiling(0x01);
- delay(1);
- }
- void main()
- {
- uchar num=0;
-
- INIT();
- while(1)
- { P3=0x00;
- ale=1;
- st=0; //此三条为启动程序
- st=1;
- st=0;
- while(!eoc); // 等待转换完毕的信号,eoc=1是转换完毕;
-
- oe=1; //输出三态门打开,将转换的结果输出到数据总线上
- getdata=P1;
- oe=0;
-
- getdata=getdata*100/51;
- tab[0]=0x30+getdata/100;
- tab[2]=0x30+getdata%100/10;
- tab[3]=0x30+getdata%10;
-
- for(num=0;num<4;num++)
- {
- wzhiling(0x80+0x00+num);
- wshuju(tab[num]);
-
- }
- }
- }
复制代码
|