The actual picture is as follows:
The circuit diagram is as follows:
The microcontroller source program is as follows:
#include
#include
#define CIRCLE 2.0 //Macro definition of the circumference of the wheel (this should be set according to the actual wheel)
sbit Signal = P1^0; //The Signal here represents the signal pin of the Hall sensor
int m_second=0; //Define variable m_second to record time (in milliseconds)
float speed=0.0 ; //Define speed variable
float length=0.0 ;//Define distance variable
void main()
{
lcd_init(); //Initialize LCD function
TMOD = 0x01; //Turn on timer 0, and set its working mode to 16-bit timing mode.
TH0=(65536-10000)/ 256;
TL0=(65536-10000)% 256; //Set the initial value of the timer so that it interrupts every 10ms
EA = 1; //Allow total interrupt
ET0 = 1; //Allow timer 0 terminal
TR0 = 1; //Start timer 0
while(1) //Large loop
{
while(Signal); //Wait for the Hall sensor signal line to be pulled low;
speed = CIRCLE *1000/ m_second ; //Calculate speed.
m_second = 0; //Reset the timer
length+=CIRCLE ; //Distance plus one wheel cycle
//First line, display speed
lcd_pos(0x00); //Set the LCD writing position to the first line and the first grid
lcd_wdat('S');
lcd_wdat('p');
lcd_wdat('e');
lcd_wdat('e');
lcd_wdat('d');
lcd_wdat(':');
lcd_wdat((int)speed/10+0x30); //Display the integer part of the speed
lcd_wdat((int)speed%10+0x30);
lcd_wdat('.');
lcd_wdat((int)(speed*10)%10+0x30 ); //Display the first decimal place of the speed lcd_wdat
('m');
lcd_wdat('/');
lcd_wdat('s');
//The second line, display mileage
lcd_pos(0x40); //Set the writing position of the LCD to the first grid of the second line
lcd_wdat('L');
lcd_wdat('e')
;
lcd_wdat('n'); lcd_wdat('g');
lcd_wdat('t')
; lcd_wdat('h');
lcd_wdat(':');
lcd_wdat((int)length /10000+0x30); //Display the ten thousandth place of mileage;
lcd_wdat((int)length %10000/1000+0x30);//Display the thousandth place of mileage;
lcd_wdat((int)length %1000/100+0x30); //Display the hundredth place of mileage;
lcd_wdat((int)length %100/10+0x30); //Display the tens digit of mileage;
lcd_wdat((int)length %10+0x30); //Display the ones digit of mileage;
lcd_wdat('m');
while(!Signal);
}
}
void timer0_intt() interrupt 1 //
{
TH0=(65536-10000)/ 256;
TL0=(65536-10000)% 256; //Set the initial value of the timer so that it interrupts every 10ms
m_second += 10; //Because the interrupt occurs every 10 milliseconds, 10 is added each time here;
}
#include
#include
/*********************************************************************************
Function:LCD delay subroutine
Entry parameter:ms
Exit parameter:
*********************************************************************************/
static void delay(unsigned char ms)
{
unsigned char i;
while(ms--)
{
for(i = 0; i< 5; i++);
}
}
/********************************************************************************
Function: Test LCD busy state
Entry parameter:
Exit parameter: result
*****************************************************************************/
static bit lcd_bz()
{
bit result;
rs = 0;
rw = 1;
ep = 1;
delay(5);
result = (bit)(P0 & 0x80);
ep = 0;
return result;
}
/*****************************************************************************
Function: Write instruction data to LCD Subroutine
Entry parameter: cmd
Exit parameter:
*****************************************************************************/
static void lcd_wcmd(unsigned char cmd)
{
while(lcd_bz()); //Judge whether LCD is busy
rs = 0;
rw = 0;
ep = 0;
delay(5);
P0 = cmd;
delay(5);
ep = 1;
delay(5);
ep = 0;
}
/********************************************************************************
Function: Set display position Subroutine
entry parameter: pos
Exit parameter:
*****************************************************************************/
void lcd_pos(unsigned char pos)
{
lcd_wcmd(pos | 0x80);
}
/*********************************************************************************
Function: Write display data to LCD Subroutine
entry parameter: dat
Exit parameter:
*****************************************************************************/
void lcd_wdat(unsigned char dat)
{
while(lcd_bz()); //Judge whether LCD is busy
rs = 1;
rw = 0;
ep = 0;
P0 = dat;
delay(5);
ep = 1;
delay(5);
ep = 0;
}
/********************************************************************************
Function: LCD initialization subroutine
entry parameter:
exit parameter:
*****************************************************************************/
void lcd_init()
{
lcd_wcmd(0x38);
delay(100);
lcd_wcmd(0x0c);
delay(100);
lcd_wcmd(0x06);
delay(100);
lcd_wcmd(0x01);
delay(100);
}
/********************************************************************************
Function: LCD writes an integer data
entry parameter: int x
*****************************************************************************/
void lcd_write_int(unsigned int x)
{
unsigned char x1,x2,x3,x4,x5;
x1 = x/10000;
x2=x%10000/1000;
x3=x%1000/100;
x4=x%100/10;
x5=x%10;
lcd_wdat(x1+0x30);
lcd_wdat(x2+0x30);
lcd_wdat(x3+0x30);
lcd_wdat(x4+0x30);
lcd_wdat(x5+0x30);
}
#ifndef __STAR1602_H__
#define __STAR1602_H__
sbit rs= P2^6; //
sbit rw = P2^5; //
sbit ep = P2^7; //
void lcd_init(); //LCD initialization function
void lcd_pos(unsigned char pos); //LCD display position setting function
void lcd_wdat(unsigned char dat); //LCD writes characters
void lcd_write_int(unsigned int x); //LCD displays an integer variable
Previous article:MCU high efficiency code reading 18B20 displayed on LCD1602
Next article:51 MCU OLED12864 I2C interface usage tutorial
- 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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Direct Memory Access (DMA) Controller - TMS320VC5509A
- A must-read for beginners! Experts explain the PCB return path for high-speed circuits
- Two major power outages in five days! The Taiwan authorities have asked TSMC to relocate or suspend some production lines
- Frequency division of analog signals
- C2000-GNAG Operation and Use
- What role does artificial intelligence play in chip development?
- HyperLynx High-Speed Circuit Design and Simulation (VI) Non-ideal Transmission Line Differential Pair Eye Diagram (Impedance Mismatch)
- [ESK32-360 Review] 6. Hello! Hello! Hello! Hello!
- [NXP Rapid IoT Review] NXP Rapid IOT Experience
- Is there any teacher who can help me write a program for Mitsubishi FX3U to output pulses?