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); }
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)
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- The largest semiconductor deal in history is born! $40 billion acquisition of ARM
- PCB design experience - for reference
- Confused, what is an oscilloscope with a Z axis? Don't worry, here is an introduction
- STM32 Hefei Seminar
- "Recommend Chinese Chip" + Minsilicon (ARM core 32-bit MCU)
- Wireless communication, 5G, RF, antenna and several concepts and indicators
- Happy Lantern Festival! Guess the lantern riddles and have fun
- How to make an automatic switch when there are 3 5V input ports on a circuit board?
- "Operational Amplifier Parameter Analysis and LTspice Application Simulation" Reading Notes Part 3 - Noise
- 280 million yuan in subsidies returned! A Russian supercomputer company's self-developed CPU failed to meet the standards and was sued by the Ministry of Industry and Trade