ADC0808采集电压并且用数码管显示仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar code DSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- sbit CLK=P1^3;
- sbit ST=P1^2;
- sbit EOC=P1^1;
- sbit OE=P1^0;
- void DelayMS(uint ms)
- {
- uchar i;
- while(ms--)
- for(i=0;i<120;i++);
- }
- /******************显示采集的电压**********************************/
- void Display_Result(uchar d)
- {
- P2=0xf7;
- P0=DSY_CODE[d%10]; //注意:当d变为2*d时候,显示正确,但不知why
- DelayMS(5);
- P2=0xfb;
- P0=DSY_CODE[d%100/10];
- DelayMS(5);
- P2=0xfd;
- P0=DSY_CODE[d/100]|0x80;
- DelayMS(5);
- }
- void main()
- {
- // uchar guo;
- TMOD=0x02;
- TH0=0x14;
- TL0=0x00;
- IE=0x82;
- TR0=1;
-
- P1=0x3f; //通道选择
-
- while(1)
- {
- ST=0;ST=1;ST=0; //ADC启动
- while(EOC==0); //转换结束信号
- OE=1; //输出使能
- // guo=(P3/256)*5*100;
- Display_Result(P3);
- OE=0;
- }
- }
- void Timer0_INT() interrupt 1
- {
- CLK=~CLK;
- }
复制代码
所有资料51hei提供下载:
ADC0808采集电压并且用数码管显示0.zip
(67.46 KB, 下载次数: 146)
|