MCU + ADC0832 simple digital voltmeter proteus simulation and program source code

Publisher:CW13236066525Latest update time:2019-12-05 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The ADC0832 voltmeter simulation schematic is as follows

The source program of the microcontroller voltmeter is as follows:

#include

#include


#define uint unsigned int

#define uchar unsigned char

        

sbit CS =P3^4; //Chip select enable terminal

sbit DI =P1^1; //Data signal input terminal, select channel control (SIG/DIF and ODD/EVEN)

sbit DO =P1^1; //data output terminal

sbit CLK =P1^0; //clock pulse


sbit S_1 = P2^3;

sbit S_2 = P2^4;

sbit S_3 = P2^5;

sbit S_4 = P2^6;


unsigned char wd[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //Segment selection code without decimal point

unsigned char yd[]={0x40,0x79,0x024,0x30,0x19,0x12,0x02,0x78,0x00,0x10}; //segment selection code with decimal point


// ===========Delay subroutine==================

void delay_ms(unsigned int x) 

{

        unsigned int i,j;

        for(i=0;i             for(j=0;j<123;j++); //delay 1ms

}

/*==============Read ADC0832 function==============*/

/*=============Collect and return=================*/

unsigned int Adc0832(unsigned char channel) //AD conversion, return result

{

    fly i=0;   

                flying j;

                uint dat=0; //Forward input data

                uchar ndat=0; //Reverse input data

//****************Initialization operation**************

                if(channel==0)channel=2;     //10B对应SGL/DIF=1,ODD/EVEN=0

                if(channel==1)channel=3;     //11B对应SGL/DIF=1,ODD/EVEN=1

//****************write operation, write channel data to ADC0832**************

           DI=1; _nop_();_nop_(); //Send start bit, fixed to 1 (1 bit)

                 CS=0;_nop_();_nop_(); //Pull the CS terminal low to enable ADC0832

                 CLK=1;_nop_();_nop_(); //Pull up the CLK terminal, and the data at the DI terminal will be moved into the multi-channel shift register inside ADC0832

                 CLK=0;_nop_();_nop_(); //Pull the CLK end low to form a falling edge 1, and the first cycle begins

                 CLK=1; //Pull up the CLK terminal. In the first clock cycle, DI is high, indicating the start position.

                                         // Then enter two configuration bits for channel selection

                        DI=channel&0x1;_nop_();_nop_(); //Assuming channel 0 is selected, 10&01=0, that is, SGL/DIF=0, which is differential input (2 bits)

                        CLK=0;_nop_();_nop_(); //Pull the CLK end low to form falling edge 2, and the second cycle begins

                        CLK=1; //Pull up the CLK terminal

                        DI=(channel>>1)&0x1;_nop_();_nop_(); //Assuming channel 0 is selected, 01&01=1, ODD/EVEN=1, indicating channel 0

            CLK=0; //Pull down the CLK end to form a falling edge 3

                        DI=1;_nop_();_nop_(); //Control command ends 

                        that=0;

                //****************Read operation, output the AD converted number from DO port****************

                        for(i=0;i<8;i++) //Output a digit at each falling edge of CLK, output the high digit first

                        {

                                 dat|=DO; //Receive data, “|” bit OR, if one of the two bits is 1, the result is 1, otherwise it is 0

                                 CLK=1;_nop_();_nop_();

                                 CLK=0;_nop_();_nop_(); //Form a clock pulse

                                 dat<<=1;

                                 if(i==7)dat|=DO;

                        } 

                        

                        for(i=0;i<8;i++) //Output a digit at each falling edge of CLK, output the low digit first

                        {

                                 j=0;

                                 j=j|DO; //Receive data

                                 CLK=1;_nop_();_nop_();

                                 CLK=0;_nop_();_nop_(); //Form a clock pulse

                                 j=j<<7;

                                 ndat=ndat|j;

                                 if(i<7)ndat>>=1;

                        }

//*********************End AD conversion and return the converted number***********************

                        CS=1; //Pull the CS terminal low

                        CLK=0; //Pull the CLK terminal low

                        DO=1; //Pull the data terminal high and return to the initial state

                        dat<<=8;

                        that|=ndat;

                        return(dat); //Return data

                        }

//============Digital tube display function===========================

        void display(uchar p) //digital tube display function

        {

        uchar S1,S2,S3;


        S1=p/51; //unit digit

        S2=(p*10/51)%10; //tenth place

        S3=(p*100/51)%10; //percentile

                

        //units

        S_1 = 1; //The first digital tube

        S_2 = 0;

        S_3 = 0;

        S_4= 0;

        P0=yd[S1]; //Select the segment code with decimal point

        delay_ms(5); //delay

        S_1 = 0; //Blanking

                

  //tenth place

        S_1 = 0;

        S_2 = 1; //Get the second digital tube

        S_3= 0;

        S_4= 0;

        P0=wd[S2]; //Select the segment code without decimal point

  delay_ms(5);

        S_2 = 0; //Blanking

        

  //Percentile

        S_1 = 0;

        S_2 = 0;

        S_3= 1; //Get the third digital tube

        S_4= 0;

        P0=wd[S3]; //Select the segment code without decimal point

        delay_ms(5);  

  S_3= 0; //Blanking

        }

//===========Main function================

        int main(void)

{

        while(1) // infinite loop

        display(Adc0832(0)); //digital tube display

//Adc0832(0): Select channel 0, single-ended mode

//Call Adc0832(0), SIG/DIF=0, ODD/EVEN=1, indicating that it works in differential input mode, and CH0 is -, CH1 is +

……………………



Keywords:MCU Reference address:MCU + ADC0832 simple digital voltmeter proteus simulation and program source code

Previous article:Single chip fully automatic washing machine program + simulation + schematic design debugging and analysis
Next article:Design report of 4-digit addition calculator based on 51 single chip microcomputer

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号