51 MCU ADC0832 voltage measurement LCD 1602 display C program and proteus simulation

Publisher:bln898Latest update time:2016-09-28 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
I have been interested in AD conversion for a long time, and I also want to make a microcontroller development board in my spare time to let the majority of electronic design enthusiasts learn to use microcontrollers.

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:

 

Search and sort out 51 single chip microcomputer ADC0832 voltage measurement LCD 1602 display C program and proteus simulation - zhangwuju0396 - I will hit the water for three thousand miles, and I will be confident that I will live for two hundred years

 

 

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 DATA)   //写数据
{

delay_10ns(50);
E=0;
Rs=1;
Rw=0; 
DD=DATA; 
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,data_c;

data_c=0;

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 ta_c=(da ta_c<<1)|ADC_DO; //DO outputs one bit of data at the falling edge of each pulse, and finally ch is an 8-bit binary number

   }

   ADC_CS=1; //Cancel chip select, a conversion cycle ends

return(da ta_c); //Return the conversion result
}


void main(void)

unsigned int data_temp=0; 
while(1)
{ data_temp=ADC0832();
   init();
xs_int(196*data_temp,1);
   }

}

The above has passed the simulation test.

Reference address:51 MCU ADC0832 voltage measurement LCD 1602 display C program and proteus simulation

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

STC51 from entry to mastery (assembly) ----Lecture 4: 80C51 microcontroller instruction system (I) Programming language and instructions
The key points to learn the command system are as follows: Function Addressing mode Number of bits and storage structure of operands Impact on PSWs Correspondence between instructions and storage areas Various pointers and the address ranges they point to Transfer range of transfer instruction Instruction Bytes and Ma
[Microcontroller]
STC51 from entry to mastery (assembly) ----Lecture 4: 80C51 microcontroller instruction system (I) Programming language and instructions
Hall Effect Bicycle Odometer Based on 51 Single Chip Microcomputer
1. Hardware Solution With 51 single chip microcomputer as the core, A44E Hall sensor measures the number of revolutions, realizes the measurement and statistics of bicycle mileage/speed, and uses digital tube to display the mileage and speed of bicycle in real time. The Hall element is used to transmit the number of p
[Microcontroller]
Hall Effect Bicycle Odometer Based on 51 Single Chip Microcomputer
51 MCU Basics (1)
1.   What is a single-chip microcomputer? What are its main features? A single-chip microcomputer, or MCU for short, is a microcomputer that integrates a microprocessor (CPU), memory (ROM and RAM for storing programs or data), bus, timer/counter, input/output interface (I/O port) and other functional devices on a si
[Microcontroller]
Based on AT89C51 single chip microcomputer, the digital tube lights up 0 to 9 in a cycle (Keil+Proteus+C language)
Requirement Description: Use AT89C51 single chip microcomputer, green 7-segment common cathode digital tube, and use C language to implement Simulation diagram Code #include reg52.h #include intrins.h #define uchar unsigned char #define uint unsigned int uchar code DSY_CODE = {   0x3f,0x06,0x5b,0x4f, 0x66,0x6d,
[Microcontroller]
Based on AT89C51 single chip microcomputer, the digital tube lights up 0 to 9 in a cycle (Keil+Proteus+C language)
51 MCU - MCU expansion external RAM - 6264 - 08
Today's work is what I did before, but it didn't work. I failed when expanding the ROM~~ However, today the main thing is to expand the external RAM, which is relatively simple. If you don't want to set up too many compilers for the external ROM~~ Microcontroller expansion of external RAM 1. Expansion bus 1. Introd
[Microcontroller]
51 MCU - MCU expansion external RAM - 6264 - 08
51 MCU-Timer
[Microcontroller]
51 MCU-Timer
Interface Design between MCS_51 Single Chip Microcomputer and 8255A
The so-called programmable interface chip refers to an interface chip whose function can be changed by the instructions of the microprocessor. By programming, an interface chip can perform different interface functions. At present, various manufacturers have provided many series of programmable interfaces. The two com
[Microcontroller]
Interface Design between MCS_51 Single Chip Microcomputer and 8255A
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号