應該還可以吧,課堂作業。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載):
0.png (36.38 KB, 下載次數: 98)
下載附件
2017-5-17 17:28 上傳
0.png (64 KB, 下載次數: 81)
下載附件
2017-5-17 17:27 上傳
單片機源程序如下:
- #include <reg52.h>
- #include <intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- sbit dat=P1^2;
- sbit sclk=P1^1;
- sbit cs=P1^0;
- uchar ad_flag;
- uint ad_value[4]={0};
- unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x3e};
- unsigned char code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed};
- unsigned char code wei[]={0x01,0x02,0x04,0x08};
- void display()
- { uchar num;
- uchar t=180;
- for(num=0;num<4;num++)
- { P0=~wei[num];
- if(num==0)
- P2=~table1[ad_value[num]];
- else
- P2=~table[ad_value[num]];
- while(t--);
- }
-
- }
- /*********AD轉換函數*************/
- uint adc0831() //根據時序圖寫出的模擬數據輸出
- {
- uchar i;
- uint temp;
- dat=1;
- sclk=0;
- cs=1; //啟動AD
- _nop_();
- _nop_();
- cs=0;
- _nop_();
- _nop_();
- sclk=0; // 第一個周期
- _nop_();
- _nop_();
- sclk=1; //
- _nop_();
- _nop_();
- sclk=0; // 第二個周期
- _nop_();
- _nop_();
- sclk=1; //
- _nop_();
- _nop_();
- sclk=0; // 第三個周期
- _nop_();
- _nop_();
- for(i=0;i<8;i++)
- {
- //高電平內接收數據
-
- temp<<=1; //ADC0831先傳輸數據高位,再傳輸數據低位
- if(dat)
- {
- temp++;
- }
- sclk=1;
- _nop_();
- _nop_();
- sclk=0;
- _nop_();
- _nop_();
- }
- cs=1;
- _nop_();
- _nop_();
- return(temp);
- }
- /*************主函數********************/
- void main()
- { uint ad,i=0;
- ad_value[3]=10;
- while(1)
- { i++;
- if(i==255)
- {
- i=0;
- ad=adc0831(); //ADzhuanhuan
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
簡易數字電壓表.rar
(21.25 KB, 下載次數: 61)
2017-5-17 17:14 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|