Today, through searching, I have compiled a C program and circuit connection diagram that can be simulated by proteus 7 based on 51 microcontroller + ADC0832 voltage acquisition and LCD 1602 voltage display. I hope it will be helpful to everyone.
It doesn't matter who wrote or modified the program. The main thing is to learn and use the microcontroller AD conversion. This is the best way.
The circuit connection diagram is as follows:
The C program is as follows:
#include
#include
#include
/**********************************8/
/**********LCD1602 interface program**********/
#define DD P2
sbit Rs=P3^0;
sbit Rw=P3^1;
sbit E=P3^2;
sbit busy_p=ACC^7;
/********************************/
void delay_1ms(unsigned char i) //最小延时1ms
{ unsigned char j;
while(i--)
for(j=0;j<125; j++);
}
void delay_10ns(unsigned char i) //最小延时10ns
{ unsigned char j;
while(i--)
for(j=0;j<10; j++);
}
void write_com(unsigned char com,bit p) //写指令
{if(p)
delay_10ns(5);
E=0;
Rs=0;
Rw=0;
DD=com;
delay_10ns(50); //>40ns
E=1;
delay_1ms(2); //>150ns
E=0;
delay_10ns(4); //>25+10ns
}
void write_date(unsigned char DA
{
delay_10ns(50);
E=0;
Rs=1;
Rw=0;
DD=DA
delay_10ns(50);
E=1;
delay_10ns(50);
E=0;
delay_10ns(4);
}
void addr_x_y(unsigned char x,bit y) //write coordinates, set position
{ unsigned char temp=0x80;
if(y)
{temp|=0x40;}
temp|=x;
write_com(temp,0);
}
void desplay_char(unsigned char x,bit y,unsigned char p)
//在指定位置显示一个字符。
{ addr_x_y(x,y);
write_date(p);
}
void init(void)
{delay_1ms(15);
write_com(0x38,0);
delay_1ms(5);
write_com(0x38,0);
delay_1ms(5);
write_com(0x38,0);
delay_1ms(5);
write_com(0x38,1);
write_com(0x08,1);
write_com(0x01,1);
write_com(0x06,1);
write_com(0x0c,1);
}
void xs_int(unsigned int shuju,bit t) //显示一个数字
{unsigned char huancun[6]={0};
unsigned char biaozhi=0,i;
if (shuju < 10) biaozhi = 1;
else if(shuju < 100) biaozhi = 2;
else if(shuju < 1000) biaozhi = 3;
else if(shuju < 10000) biaozhi = 4;
else if(shuju < 65535) biaozhi = 5;
switch(biaozhi)
{case 5:huancun[5] = shuju/10000;
case 4:huancun[3] = shuju%10000/1000;
case 3:huancun[2] = shuju%1000/100;
case 2:huancun[1] = shuju%100/10;
case 1:huancun[0] = shuju%10;
break;
default:break;
}
for(i=6;i>1;i--)
{if(i==5)desplay_char(10,1,'.');
else desplay_char(15-i,t,0x30+huancun[i-1]); }
desplay_char(15,t,'V');
}
/****************************************************************/
/**********ADC0832 interface program****************************************/
sbit ADC_CS =P3^4;
sbit ADC_CLK=P3^5;
sbit ADC_DO =P3^6;
sbit ADC_DI =P3^7;
/*******************************************************************/
void Delay(unsigned char j)
{
unsigned char i;
for(i=0;i } unsigned char ADC0832(void) //Convert the analog voltage value into an 8-bit binary number and return it { unsigned char i,da da ADC_CS=0; ADC_DO=0; //Chip select, DO is high impedance for(i=0;i<10;i++) {;} ADC_CLK=0; Delay(2); ADC_DI=1; ADC_CLK=1; Delay(2); //First pulse, start bit ADC_CLK=0; Delay(2); ADC_DI=1; ADC_CLK=1; Delay(2); //The second pulse, DI=1 indicates dual-channel unipolar input ADC_CLK=0; Delay(2); ADC_DI=1; ADC_CLK=1; Delay(2); //The third pulse, DI=1 means selecting channel 1 (CH2) ADC_DI=0; ADC_DO=1; //DI turns to high impedance state, DO leaves high impedance state to prepare for output data ADC_CLK=1; Delay(2); ADC_CLK=0; Delay(2); //According to the experiment, adding a pulse AD here can correctly read the data. //If not added, the read data will be one bit less (the lowest bit d0 cannot be read) for (i=0; i<8; i++) { ADC_CLK=1; Delay(2); ADC_CLK=0; Delay(2); da } ADC_CS=1; //Cancel chip select, a conversion cycle ends return(da } The above has passed the simulation test.
}
void main(void)
{
unsigned int da
while(1)
{ da
init();
xs_int(196*da
}
Previous article:51 MCU serial port sends string to computer C program
Next article:The use of common functional modules of single chip microcomputer Part 8. Speaker
Recommended ReadingLatest update time:2024-11-15 18:22
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- Single-chip microcomputer C language programming and simulation
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Fundamentals and Applications of Single Chip Microcomputers (Edited by Zhang Liguang and Chen Zhongxiao)
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
- Ranking of installed capacity of smart driving suppliers from January to September 2024: Rise of independent manufacturers and strong growth of LiDAR market
- Industry first! Xiaopeng announces P7 car chip crowdfunding is completed: upgraded to Snapdragon 8295, fluency doubled
- P22-009_Butterfly E3106 Cord Board Solution
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- [Raspberry Pi Pico Review] Unable to identify USB serial port
- Design and Implementation of Secondary Bootloader for TMS320C6000 Series
- What exactly is the input and output voltage range of an operational amplifier?
- Micropython version that supports MCPWM function
- How to solve the problem of No rule to make target when developing zynq using xilinx SDK
- Design of control system for CNC engraving machine based on embedded system
- Development environment installation (II) Cross-compilation environment
- Interpretation and test application of IEC harmonic standards
- VICOR engineers invite you to chat: How to improve the throughput and running time of automatic test equipment?
- The price has increased by at least 200 times! Identification of popular chip material numbers from TI, ST, Infineon, and Qualcomm