Single chip computer bicycle speed measurement system + source program + proteus simulation

Publisher:糖三角Latest update time:2019-12-11 Source: elecfansKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The simulation schematic diagram of the bicycle speed measurement system is as follows

The microcontroller source program is as follows:

#include "d:c51reg51.h"

#include "d:c51intrins.h"



sbit LCM_RS=P3^0;

sbit LCM_RW=P3^1;

sbit LCM_EN=P3^7;


#define BUSY 0x80 //Constant definition

#define DATAPORT P1

#define uchar unsigned char

#define uint unsigned int

#define L 50


uchar str0[16],str1[16],count;

uint speed;

unsigned long time;


void ddelay(uint);

void lcd_wait(void);

void display();

void initLCM();

void WriteCommandLCM(uchar WCLCM,uchar BusyC);

void STR();

void account();



/*********Delay K*1ms,12.000mhz**********/


void int0_isr(void) interrupt 0 /*Remote control uses external interrupt 0, connected to P3.2 port*/

{

    unsigned int temp;

        time=count;

    TR0=0;

        temp=TH0;

        temp=((temp << 8) | TL0);

    TH0=0x3c;

    TL0=0xaf;

        count=0;

    TR0=1;

        time=time*50000+temp;

}


void time0_isr(void) interrupt 1 /*Remote control uses timer counter 1 */

{

   TH0 = 0x3c;

   TL0 = 0xaf;

   count++;

}


void main(void)

{

           TMOD=0x01; /*TMOD T0 selects mode 1 (16-bit timing) */

    IP|=0x01; /*INT0 interrupt priority*/

    TCON|=0x11; /*TCON EX0 falling edge trigger, start T0*/

    IE|=0x83;  

    TH0=0x3c;

    TL0=0xaf;

  

        initLCM();

           WriteCommandLCM(0x01,1); //Clear the display screen

        for(;;)

        {

                account();

                display();

        }

}


void account()

{

        unsigned long a; 

        if (time!=0)

        {

                a=L*360000000/time;

        }

        speed=a;

}




void STR()

{

        str0[0]='S';

        str0[1]='p';

        str0[2]='e';

    str0[3]='e';

        str0[4]='d';

        str0[5]=' ';        

        str0[6]=(speed%100000)/10000+0x30;

        str0[7]=(speed%10000)/1000+0x30;

        str0[8]=(speed%1000)/100+0x30;

        str0[9]='.';

        str0[10]=(speed%100)/10+0x30;

        str0[11]=speed%10+0x30;

        str0[12]='k';

        str0[13]='m';

        str0[14]='/';

        str0[15]='h';

}


void ddelay(uint k)

{

    uint i,j;

    for(i=0;i    {

        for(j=0;j<60;j++)

                {;}

    }

}

/**********Write instructions to LCD sub-function************/


void WriteCommandLCM(uchar WCLCM,uchar BusyC)

{

    if(BusyC)lcd_wait();

        DATAPORT=WCLCM;

    LCM_RS=0; /* Select instruction register */

    LCM_RW=0; // Write mode

    LCM_EN=1;

        _nop_();

        _nop_();

        _nop_();

    LCM_EN=0;


}


/**********Write data to LCD sub-function************/


void WriteDataLCM(uchar WDLCM)

{

    lcd_wait(); //Detect busy signal

        DATAPORT=WDLCM;

    LCM_RS=1; /* Select data register */

    LCM_RW=0; // Write mode

    LCM_EN=1;

    _nop_();

        _nop_();

        _nop_();

    LCM_EN=0;

}


/***********lcd internal waiting function*************/


void lcd_wait(void)

{

    DATAPORT=0xff; //If the MCU outputs a low level before reading the LCD, and the LCD reads a high level, there will be a conflict, and the Proteus simulation will display the logic yellow

        LCM_EN=1;

    LCM_RS=0;

    LCM_RW=1;

    _nop_();

    _nop_();

        _nop_();

    while(DATAPORT&BUSY)

        { LCM_EN=0;

           _nop_();

           _nop_();

           LCM_EN=1;

           _nop_();

           _nop_();

        }

           LCM_EN=0;


}


/**********LCD initialization subfunction***********/

void initLCM( )

{

        DATAPORT=0;

        ddelay(15);

        WriteCommandLCM(0x38,0); //Three times display mode setting, do not detect busy signal

    ddelay(5);

    WriteCommandLCM(0x38,0);

    ddelay(5);

    WriteCommandLCM(0x38,0);

    ddelay(5);


    WriteCommandLCM(0x38,1); //8bit data transmission, 2 lines display, 5*7 font, detect busy signal

    WriteCommandLCM(0x08,1); //Turn off the display and detect the busy signal

    WriteCommandLCM(0x01,1); //Clear the screen and detect busy signal

    WriteCommandLCM(0x06,1); //Display cursor right shift setting, detect busy signal

    WriteCommandLCM(0x0c,1); //Display screen is turned on, cursor is not displayed, not blinking, busy signal is detected

}


/****Display a character subfunction at the specified coordinate****/


void DisplayOneChar(uchar X,uchar Y,uchar DData)

{

    Y&=1;

    X&=15;

    if(Y)X|=0x40; //If y is 1 (display the second line), address code + 0X40

    X|=0x80; //Instruction code is address code + 0X80

    WriteCommandLCM(X,0);

    WriteDataLCM(DData);

}


/*******Display a string of characters at the specified coordinates subfunction*****/


void DisplayListChar(uchar X,uchar Y,uchar *DData)

{

    uchar ListLength=0;

    Y&=0x01;

    X&=0x0f;

    while(X<16)

    {

        DisplayOneChar(X,Y,DData[ListLength]);

        ListLength++;

        X++;

    }

}



void display()

{


        STR(); 

        DisplayListChar(0,0,str0);

           DisplayListChar(0,1,str1);

}



Keywords:MCU Reference address:Single chip computer bicycle speed measurement system + source program + proteus simulation

Previous article:GP2Y0E02B distance measurement module 89c52 microcontroller serial port program
Next article:MCU + ULN2003A stepper motor control system (forward and reverse + acceleration and deceleration)

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号