目录
一、主要功能
二、硬件资源
三、程序编程
四、实现现象
一、主要功能
基于51单片机,通过ADC0808获取两路电压,通过LCD1602显示
二、硬件资源
基于KEIL5编写C++代码,PROTEUS8.15进行仿真,全部资源在页尾,提供安装包。
编辑
三、程序编程
#include <REGX52.H>#include "intrins.h"#include "LCD1602.h"sbit CLOCK = P2^4;
sbit ST = P2^5;
sbit EOC =P2^6;
sbit OE = P2^7;
sbit aa = P3^4;
sbit bb = P3^5;
sbit cc = P3^6;#define uchar unsigned char#define uint unsigned int
int i =0;
uchar value;
uchar A1\[3\],A2\[3\];
unsigned int ADC,ADC1;void delay(char x);void Timer0_INT() interrupt 1{
CLOCK = !CLOCK;
}void main(){
TMOD = 0x02;
TH0 = 0x20;
TL0 = 0x00;
IE = 0x82;
EA = 1; // 总中断开关
ET0 = 1; // T0定时器总中断开关
TR0 = 1; LCD\_Init(); LCD\_ShowString(1,1,"-----DIANYA-----"); while(1)
{ for(i=0;i<25;i++)
{
aa=0;bb=0;cc=0;
ST = 1;
ST = 0; while(EOC == 0);//正在转换
{
OE = 1;
}
ADC = P1;//ADC转换结果
OE=0; delay(10);
ADC= ADC*1.96;
A1\[0\]= ADC/100;
A1\[1\]= (ADC/10)%10;
A1\[2\]= ADC%100; LCD\_ShowNum(2,1,A1\[0\],1); LCD\_ShowString(2,2,"."); LCD\_ShowNum(2,3,A1\[1\],1); LCD\_ShowNum(2,4,A1\[2\],1); LCD_ShowString(2,5,"V");
}
for(i=0;i<25;i++)
{
aa=1;bb=0;cc=0;
ST = 1;//产生启动转换的正脉冲信号
\_nop\_();
ST = 0;
\_nop\_(); while(EOC == 0);//正在转换
{
OE = 1;
}
ADC1 = P1;//ADC转换结果
OE=0; delay(10);
ADC1 = ADC1*1.96;
A2\[0\]= ADC1/100;
A2\[1\]= (ADC1/10)%10;
A2\[2\]= ADC1%100; LCD\_ShowNum(2,10,A2\[0\],1); LCD\_ShowString(2,11,"."); LCD\_ShowNum(2,12,A2\[1\],1); LCD\_ShowNum(2,13,A2\[2\],1); LCD_ShowString(2,14,"V");
}
}
}void delay(char x){ int i, k; for(i = 0; i < x; i++) for(k = 0; k < 120; k++);
}
四、实现现象
具体动态效果看B站演示视频:
基于51单片机的两路电压检测(ADC0808)
全部资料(源程序、仿真文件、安装包、演示视频):
百度网盘资料下载