標題:
基于adc0809和51單片機檢測電源電壓并顯示(4位數(shù)碼管)
[打印本頁]
作者:
1303579571
時間:
2019-1-13 11:09
標題:
基于adc0809和51單片機檢測電源電壓并顯示(4位數(shù)碼管)
0.png
(39.78 KB, 下載次數(shù): 34)
下載附件
2019-1-13 15:04 上傳
單片機源程序如下:
//程序頭函數(shù)
#include <reg52.h>
//宏定義
#define uint unsigned int
#define uchar unsigned char
#define Data_ADC0809 P1
//ADC0809
sbit ST=P3^2;
sbit EOC=P3^3;
sbit OE=P3^1;
sbit DIAN = P0^5; //小數(shù)點
/*******************************定義全局變量********************************/
unsigned char dis[3]; //顯示數(shù)值
unsigned int sum=0;
unsigned int temp=0;
unsigned int dat=0;
/*******************************共陰LED段碼表*******************************/
unsigned char code tab[]={0x5F,0x44,0x9D,0xD5,0xC6,0xD3,0xDB,0x47,0xDF,0xD7,0x5e/*字母U*/}; //gc.debfa
/****************************************************************************
函數(shù)功能:AD轉(zhuǎn)換子程序
****************************************************************************/
//ADC0809讀取信息
uchar ADC0809()
{
uchar temp_=0x00;
//初始化高阻太
OE=0;
//轉(zhuǎn)化初始化
ST=0;
//開始轉(zhuǎn)換
ST=1;
ST=0;
//外部中斷等待AD轉(zhuǎn)換結(jié)束
while(EOC==0)
//讀取轉(zhuǎn)換的AD值
OE=1;
temp_=Data_ADC0809;
OE=0;
return temp_;
}
/****************************************************************************
函數(shù)功能:延時子程序
入口參數(shù):
出口參數(shù):
****************************************************************************/
void delay(unsigned int x)
{
unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<121;j++);
}
//=====================================================================================
//=====================================================================================
//=====================================================================================
/****************************************************************************
函數(shù)功能:將0-255級換算成0.00-5.00的電壓數(shù)值
入口參數(shù):i
出口參數(shù):
****************************************************************************/
void convdata(unsigned char dat1)
{
unsigned int Vo;
Vo=dat1*1.96;
dis[0] = Vo/100; //十位
dis[1] = Vo%100/10; //個位
dis[2] = Vo%100%10; //小數(shù)點后第1位
}
/****************************************************************************
函數(shù)功能:數(shù)碼管顯示子程序
入口參數(shù):
出口參數(shù):
****************************************************************************/
void display(void)
{
P0=~tab[dis[0]];
P2=0xfe; //11011111
DIAN=0;
delay(1);
P2=0xff;
P0=~tab[dis[1]];
P2=0xfb; //10111111
delay(1);
P2=0xff;
P0=~tab[dis[2]];
P2=0xef; //01111111
delay(1);
P2=0xff;
P0=~tab[10];
P2=0xbf;
delay(1);
P2=0xff;
}
/****************************************************************************
函數(shù)功能:主程序
入口參數(shù):
出口參數(shù):
****************************************************************************/
void main(void)
{
unsigned char p=0;
while(1) //主循環(huán)
{
for(p=0;p<20;p++)
{
sum=sum+ADC0809();
display();
}
// dat=((sum/20)+dat)/2;
dat=sum/20;
convdata(dat); //數(shù)據(jù)轉(zhuǎn)換
sum=0;
display(); //顯示數(shù)值
}
}
復(fù)制代碼
全部資料51hei下載地址:
原理圖.docx
(49.81 KB, 下載次數(shù): 24)
2019-1-13 11:07 上傳
點擊文件名下載附件
原理圖
下載積分: 黑幣 -5
作者:
夜默
時間:
2022-1-13 20:26
問一下能不能測量交流電電壓值
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1