Homemade single chip microcomputer STC12C5A60S2+1602 voltmeter

Publisher:BeaLaity0170Latest update time:2020-09-17 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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                for(j=0;j<123;j++);

        }


/******************************

                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);

        }


Keywords:MCU Reference address:Homemade single chip microcomputer STC12C5A60S2+1602 voltmeter

Previous article:Simulation Design of Waveform Generator Based on Single Chip Microcomputer
Next article:STC15 MCU uses ESP8266 to control LED source code

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号