001_89C52之_Proteus_ADC0809采集电压
一)使用ADC0809采集直流电压
1. 第一个数码管显示的是采样输入口
2. 后面三位是采样电压
(二)使用ADC0809进行交流电的采样
1. 先进行交流电降压,即用变压器降压后使用整桥电路进行整流
2. 默认将220交流电整流成5V最高,然后接入ADC0809
3. 图中有理论公式,大概公式可以使用,设X是读取到的电压:实际值=(X/5)*220
(三)单片机程序
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /*************** writer:shopping.w ******************/ 2 #include <reg52.h> 3 #define uint unsigned int 4 #define uchar unsigned char 5 #define DATA P1 6 sbit OE = P2^5; 7 sbit EOC = P3^3; 8 sbit ST = P2^7; 9 10 sbit C1 = P3^0; 11 sbit C2 = P3^1; 12 sbit C3 = P3^2; 13 14 uint display_data = 0; /*显示数据*/ 15 uchar code LEDData[]= 16 { 17 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f 18 }; 19 20 21 void DelayMS(uint ms) 22 { 23 uchar i; 24 while(ms--) 25 { 26 for(i=0;i<120;i++); 27 } 28 } 29 30 void Display_Result(uint d) 31 { 32 33 P2 = 0xf7; 34 P0 = LEDData[d%10]; 35 DelayMS(5); 36 P2 = 0xfb; 37 P0 = LEDData[d%100/10]; 38 DelayMS(5); 39 P2 = 0xfd; 40 P0 = (LEDData[d/100]| 0x80); 41 DelayMS(5); 42 43 P2 = 0xfe; 44 P0 = LEDData[3]; 45 DelayMS(5); 46 47 } 48 49 void main() 50 { 51 52 53 C1 = 1; 54 C2 = 1; 55 C3 = 0; 56 57 while(1) 58 { 59 ST = 0; 60 ST = 1; 61 ST = 0; 62 while(EOC == 0); 63 OE = 1; 64 display_data = ((5.0/255) * DATA) * 100; 65 Display_Result(display_data); 66 OE = 0; 67 } 68 }
(四)工程源码下载地址:
https://download.csdn.net/download/xiaoguoge11/10742910