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:
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. Some of the code is as follows: // // #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
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
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
- MCU Principles and Interface Technology C51 Programming (Edited by Zhang Yigang)
- Principles and Applications of Single Chip Microcomputers (Sun Baofa)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Help! Why can the command sent by the microcontroller only display up to the fourth step?
- Future Outlook of IoT
- msp430g2553 hardware IIC
- EM78P458 chip
- The role, advantages and disadvantages of solid-state relays
- MicroPython several issues
- ST NUCLEO-H743ZI Review Summary
- Use the RVB2601 to make a high-precision network timing clock
- What issues should be paid attention to when using a wireless bridge for one-to-many connection?
- Security engineering contractors are still using the traditional old method to quote. Come in and see if this works!