一)使用ADC0809采集直流电压
(二)使用ADC0809进行交流电的采样
(三)单片机程序
/*************** writer:shopping.w ******************/
#include
#define uint unsigned int
#define uchar unsigned char
#define DATA P1
sbit OE = P2^5;
sbit EOC = P3^3;
sbit ST = P2^7;
sbit C1 = P3^0;
sbit C2 = P3^1;
sbit C3 = P3^2;
uint display_data = 0; /*显示数据*/
uchar code LEDData[]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
};
void DelayMS(uint ms)
{
uchar i;
while(ms--)
{
for(i=0;i<120;i++);
}
}
void Display_Result(uint d)
{
P2 = 0xf7;
P0 = LEDData[d%10];
DelayMS(5);
P2 = 0xfb;
P0 = LEDData[d%100/10];
DelayMS(5);
P2 = 0xfd;
P0 = (LEDData[d/100]| 0x80);
DelayMS(5);
P2 = 0xfe;
P0 = LEDData[3];
DelayMS(5);
}
void main()
{
C1 = 1;
C2 = 1;
C3 = 0;
while(1)
{
ST = 0;
ST = 1;
ST = 0;
while(EOC == 0);
OE = 1;
display_data = ((5.0/255) * DATA) * 100;
Display_Result(display_data);
OE = 0;
}
}
(四)工程源码下载地址:
https://download.csdn.net/download/xiaoguoge11/10742910