LCD1602 D0~D7 connect to P0 port, RS=P3.1, RW=P3.2, sbit E=P3.3.
Voltage test port connects to P1.0. The power supply voltage must be stable at 5V to measure accurately. In addition, because there is no resistor, only voltage below 5V can be measured.
Without further ado, here are the pictures.
The microcontroller source program is as follows:
#include "reg51.h"
#include "intrins.h"
#define LCD P0 //LCD1602 data interface
sbit RS=P3^1; //Set RS pin interface, RS=0, instruction register; RS=1, data register
sbit RW=P3^2; //Set the R/W pin interface, R/W=0, write; R/W=1, read
sbit E=P3^3; //Set E pin interface, E allows signal
/*Declare SFR associated with the ADC */
sfr ADC_CONTR=0xBC; //ADC control register
sfr ADC_RES=0xBD; //ADC high 8-bit result register
sfr ADC_LOW2=0xBE; //ADC low 2-bit result register
sfr P1ASF=0x9D; //P1 secondary function control register
unsigned char V[]="000000";
unsigned int ADC_temp=0;
/*Define ADC operation const for ADC_CONTR*/
#define ADC_POWER 0x80 //ADC power control bit
#define ADC_FLAG 0x10 //ADC complete flag
#define ADC_START 0x08 //ADC start control bit
#define ADC_SPEEDLL 0x00 //420 clocks
#define ADC_SPEEDL 0x20 //280 clocks
#define ADC_SPEEDH 0x40 //140 clocks
#define ADC_SPEEDHH 0x60 //70 clocks
/******************************
Delay function
******************************/
void Delay(unsigned int n)
{
unsigned int i=0,j=0;
for(i=0;i } /****************************** Initialize ADC ******************************/ void InitADC() { P1ASF=0xff; ADC_RES=0; ADC_CONTR=ADC_POWER | ADC_SPEEDLL; Delay(2); } /****************************** Reading ADC ******************************/ unsigned char GetADCResult(unsigned char ch) { ADC_CONTR=ADC_POWER | ADC_SPEEDLL | ch | ADC_START; _nop_(); _nop_(); _nop_(); _nop_(); while (!(ADC_CONTR & ADC_FLAG)); ADC_CONTR &=~ADC_FLAG; return ADC_RES; } /****************************** LCD Busy Detection ******************************/ void CheckBusy(void) { unsigned int nTimeOut=0; RS=0; RW=1; E=0; E=1; while((LCD&0x80)&&(++nTimeOut !=0)); E=0; RS=0; RW=1; } /****************************** LCD sends commands or data ******************************/ void SendCmdorData(unsigned char byCmdorData,bit DI) { CheckBusy(); RS=DI; RW=0; E=0; LCD=byCmdorData; Delay(5); E=1; Delay(5); E=0; RW=1; RS=0; } /****************************** LCD Initialization Sub ******************************/ void Init(void) { SendCmdorData(0x38,0); Delay(50); SendCmdorData(0x01,0); Delay(50); SendCmdorData(0x06,0); Delay(50); SendCmdorData(0x0c,0); Delay(50); } /****************************** Address Translation ******************************/ void SetAddress(unsigned char x,y) { unsigned char byAddress; switch(x) { case 1: byAddress=0x80+y; break; case 2: byAddress=0xC0+y; break; default:break; } SendCmdorData(byAddress,0); }
Previous article:Simulation Design of Waveform Generator Based on Single Chip Microcomputer
Next article:STC15 MCU uses ESP8266 to control LED source code
- Popular Resources
- Popular amplifiers
- 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
- Learn MSP430F5529 programming routines
- Diode as a temperature compensation circuit for transistors
- Using FPGA to realize accurate time keeping when GPS is out of step
- Design of Phase Detection Broadband Frequency Measurement System Based on FPGA
- Frequency converter, inverter circuit
- 【RPi PICO】Soil Moisture Indicator
- Gaoyun Yunyuan software edits multiple lines at the same time, and the problem of Chinese input method
- Raspberry Pi Windows IoT Development (Part 3) Flashing LED
- If you are doing technology, you must learn to read datasheets!
- Programming the pyboard with Arduino