Design of automatic digital voltmeter based on 51 single chip microcomputer and ADC0808 ADC0809

Publisher:fnfeecjknqucLatest update time:2022-01-16 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Preface:

Previously, we talked about the automatic digital voltmeter based on the digital tube display. Next, let’s talk about the related designs based on LCD1602 display, which use TI’s ADC0808 and ADC0809 respectively.


Hardware and software design

Based on 51 MCU + ADC0808 + LCD1602, the test voltage range is 2.1~25V (if it exceeds this range, the program will be stuck), and the accuracy is less than 0.05


The simulation diagram is as follows:

insert image description here
insert image description here

Some of the code is as follows:


#include  


#define LEDDATA P0

#define v20_on {s3=0;s2=0;s1=1;} //Macro defines different ranges and different switch states

#define v2_on {s3=0;s2=1;s1=0;}

#define v02_on {s3=1;s2=0;s1=0;}

unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};

unsigned char dispbuf[8]={0,0,0,0,0,0,0,0};

unsigned char getdata;

unsigned long temp;

unsigned char i,k,l,m;

unsigned char code  mytable0[]=" Welcome to use  ";

unsigned char code  mytable1[]="Auto Voltmeter!";

unsigned char code line0[]=" Voltmeter "; //Initialize display 

unsigned char code line1[]=" Value:     V ";

//Pin definition

sbit lcdrs=P2^0;

sbit lcden=P2^1;

sbit s3=P3^7;  

sbit s2=P3^6;

sbit s1=P3^5;

sbit OE=P3^0; 

sbit EOC=P3^1;

sbit ST=P3^2;


void delay(unsigned int z) //delay sub-function z*1ms 

{

unsigned int x,y;

for(x=z;x>0;x--)

for(y=110;y>0;y--);

}

void write_com(unsigned char c) //write command subfunction 

{

lcdrs=0; //Low level selects write instruction 

lcden=0;                

LEDDATA=c; //Write the command into port P0 

delay(5); //Refer to the timing diagram 

lcden=1; //enable 

delay(5); //Read instruction 

lcden=0; //disable enable  


void write_data(unsigned char d) //write data sub-function 

{

lcdrs=1; //High level selects writing data 

LEDDATA=d; //Write data into P0 port 

delay(5); //Refer to the timing diagram 

lcden=1; //enable 

delay(5); //Read data 

lcden=0;          //disable enable 

void initialize() //LCD initialization function 

{   

    unsigned char num;

lcden=0;

write_com(0x38); //Set 16x2 display, 5x7 dot matrix display, 8-bit data interface 

write_com(0x0c); //00001DCB, D (display on/off), C (whether to display the cursor), B (cursor flashes, cursor does not display) 

write_com(0x06); //000001N0, N (address pointer +-1)

write_com(0x01); //Clear screen command The screen must be cleared each time the next screen content is displayed            

write_com(0x80+0x10); //First line, display at the top of the grid   

for(num=0;num<17;num++)        

{

write_data(mytable0[num]); 

delay(10);

}

write_com(0x80+0x50); //The second line, starting from the first grid 

for(num=0;num<15;num++)       

{

write_data(mytable1[num]); 

delay(10); 

}

for(num=0;num<16;num++)

{

write_com(0x1c); //0001(S/C)(R/L)**; S/C: high level moves characters, low level moves cursor; R/L: high level moves left, low level moves right 

delay(300);

}

   delay(1000); 

             

write_com(0x01); //Clear screen command The screen must be cleared each time the next screen content is displayed 

write_com(0x80);           

for(num=0;num<14;num++)     

{

write_data(line0[num]);

delay(10);

}


write_com(0x80+0x40);         

for(num=0;num<15;num++)        

{

write_data(line1[num]);

delay(10);

}


Based on 51 single chip microcomputer + ADC0809 + LCD1602, the test voltage range is 0~5V, and the accuracy is about 0.01

The AT89C51 single-chip microcomputer is the core and plays a control role. The system includes LCD1602 liquid crystal display circuit, reset circuit, clock circuit, and analog-to-digital conversion circuit. The design idea is divided into five modules: reset circuit, crystal oscillator circuit module, AT89C51, LCD1602 liquid crystal display circuit, and analog-to-digital converter circuit.

insert image description here
insert image description here

Some of the code is as follows:


//: Digital voltmeter **

//: Use LCD to display the detected voltage, with an accuracy of 0.05V and a range of 0 to 5V. **

#include"includes.h"

#define TIME0H 0x3C

#define TIME0L 0xB0

uchar uc_Clock=0; //Timer 0 interrupt count

bit b_DATransform=0;

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<把电压显示在LCD上>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

void vShowVoltage(uint uiNumber)

{

float ucaNumber[3],ucCount;

if(uiNumber>999)

uiNumber=999;

ucaNumber[0]=uiNumber/100; //Store each digit of the calculated number into the array.

ucaNumber[1]=(uiNumber-100*(int)ucaNumber[0])/10;

ucaNumber[2]=uiNumber-100*(int)ucaNumber[0]-10*ucaNumber[1];

for(ucCount=0;ucCount<3;ucCount++)

{

vShowOneChar(ucaNumber[ucCount]+48); //Output one by one from the first digit to the last digit.

if(ucCount==0)

vShowOneChar('.');

}

}

//*************************************************************************************************

//*   *

//*   ********************************Main function******************************   *

//*   *

//*************************************************************************************************

void main()

{

TMOD=0x01; //Timer 0, mode 1.

TH0=TIME0H;

TL0=TIME0L;

TR0=1; //Start the timer.

ET0=1; //Turn on timer interrupt.

EA=1; //Open the general interrupt

vdInitialize();

vWriteCMD(0x84);    //Write the display start address (the 4th position in the first line)

vShowChar("voltage");

vWriteCMD(0xC9);     

vShowChar("(V)");

while(1)

{

if(b_DATransform==1)

{

b_DATransform=0;

vWriteCMD(0xC4);

vShowVoltage(uiADTransform());

}

}

}

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<定时器0中断函数>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

void t0() interrupt 1

{

if(uc_Clock==0)

{

uc_Clock=5;

b_DATransform=1;

}

else

uc_Clock--;

TH0=TIME0H;    //Restore timer 0.

TL0=TIME0L;

}


File address:

Link: https://pan.baidu.com/s/146k5nKjulFsZeTJUKEvQDQ

Extraction code: cukz

Reference address:Design of automatic digital voltmeter based on 51 single chip microcomputer and ADC0808 ADC0809

Previous article:Design of sound noise decibel detection, collection and display based on 51 single chip microcomputer
Next article:Assembly language design of digital voltage meter digital tube based on 51 single chip microcomputer and ADC0808

Recommended ReadingLatest update time:2024-11-15 07:41

ADC0808 Program Based on AT89C51 Microcontroller
Introduction to AT89C51 Microcontroller AT89C51 is a low voltage, high performance CMOS 8-bit microprocessor with 4K bytes of flash programmable and erasable read only memory (FPEROM), commonly known as a single chip microcomputer. The device is manufactured using ATMEL's high-density non-volatile memory manufacturing
[Microcontroller]
ADC0808 Program Based on AT89C51 Microcontroller
Proteus simulation based on 51 single chip microcomputer ADC0808
Use the IN0 channel of ADC0808, input CLOCK is 500KHZ, and use AT89C51 microcontroller ADDA, ADDB, and ADDC of ADC0808 are 000, corresponding to channel IN0 ADDA, ADDB, ADDC of ADC0808 are 001 corresponding to channel IN1 The ADDA, ADDB, and ADDC of ADC0808 are 010, which corresponds to channel IN2 and is intern
[Microcontroller]
Proteus simulation based on 51 single chip microcomputer ADC0808
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号