Please download the circuit diagram and simulation files from http://www.51hei.com/bbs/dpj-20396-1.html
The
following is the program source code:
#include "d:c51 eg51.h"
#include "d: c51 intrins.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
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++)
{;}
}
}[page]
/**********Write instructions to LCD sub-function************/
void WriteCommandLCM(uchar WCLCM,uchar BusyC)
{
if(BusyC)lcd_wait();
DATAPORT=WCLCM;
LCM_RS=0; /* Select command 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 LCD , and the LCD is read as 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 sub-function***********/
void initLCM()
{
DATAPORT=0;
ddelay(15);
WriteCommandLCM(0x38,0); //Three display mode settings, do not detect busy signal
ddelay(5);
WriteCommandLCM(0x38,0);
ddelay(5);
WriteCommandLCM(0x38,0);
ddelay(5);
WriteCommandLCM(0x38,1); //8-bit data transmission, 2-line display, 5*7 font, detect busy signal
WriteCommandLCM(0x08,1); //Display off, detect busy signal
WriteCommandLCM(0x01,1); //Clear screen, 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, does not flash, detect busy signal
}
/****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; //The 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:ds1302 clock program controlled by microcontroller with alarm function
Next article:51 MCU drives ds1302 program (12864 LCD display)
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- USB Type-C® and USB Power Delivery: Designed for extended power range and battery-powered systems
- RAQ #223: How to measure and determine soft-start timing without a soft-start equation?
- RAQ #223: How to measure and determine soft-start timing without a soft-start equation?
- GigaDevice's full range of automotive-grade SPI NOR Flash GD25/55 wins ISO 26262 ASIL D functional safety certification
- GigaDevice's full range of automotive-grade SPI NOR Flash GD25/55 wins ISO 26262 ASIL D functional safety certification
- New IsoVu™ Isolated Current Probes: Bringing a New Dimension to Current Measurements
- New IsoVu™ Isolated Current Probes: Bringing a New Dimension to Current Measurements
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- STMicroelectronics IO-Link Actuator Board Brings Turnkey Reference Design to Industrial Monitoring and Equipment Manufacturers
- Mathematics is not a formula, but a way of thinking
- Considerations for selecting solid-state relays
- Application skills/Implementation of AC sampling technology in power monitoring system based on single chip microcomputer
- OMAPL138 Learning ---- Codec Engine xDAIS
- A simple explanation of Tensorflow principles and Python code examples
- Please help me, compile problem
- Air conditioning fan control panel
- IoT Communication Protocol
- 【GD32F350 LogicKids】Download the first APP program
- CC2500 rate problem