51 single chip 1602 display ultrasonic ranging source program

Test - lowercase jpg
Kaixin micro test
Test probe P100-M3
Filter 18.432M

The development of an ultrasonic rangefinder is a great hands-on project for students and electronics enthusiasts who are interested in learning about microcontroller programming. This project is specifically designed to work with the widely used HC-SR04 ultrasonic sensor module. The system uses a 1602 LCD display to show the measured distance, and it's based on the 51 series microcontroller. The ultrasonic module is connected to the microcontroller via P2.5 (TRIG) and P3.2 (ECHO). When the measured distance exceeds the maximum range, the display shows a hyphen (-), and the unit of measurement is in centimeters. Due to its simple hardware design, this project requires minimal soldering and has a high success rate. It can also be simulated using PROTEUS software for testing purposes before building the physical circuit. The code includes functions for initializing the LCD, triggering the ultrasonic sensor, measuring the time of flight, calculating the distance, and displaying the result on the screen. An interrupt service routine is used to count the time intervals accurately.
#include // Please note: change '[' to '<<' #include // #define uint unsigned int #define uchar unsigned char sbit rs = P2^0; // LCD RS pin sbit rw = P2^1; // LCD RW pin sbit en = P2^2; // LCD EN pin sbit trig = P2^5; // Ultrasonic TRIG pin sbit echo = P3^2; // Ultrasonic ECHO pin bit flag1; // Trigger signal flag uchar count; // Timer interrupt counter long int distance; // Measured distance unsigned char code table[] = {"0123456789"}; // Character array for digits void delay(uint n) { uint x, y; for(x = n; x > 0; x--) for(y = 110; y > 0; y--); } void delayt(uint x) { uchar j; while(x--) { for(j = 0; j < 255; j++); } } void lcd_wcom(uchar com) { rs = 0; rw = 0; P0 = com; delay(5); en = 1; en = 0; } void lcd_wdat(uchar dat) { rs = 1; rw = 0; P0 = dat; delay(5); en = 1; en = 0; } void lcd_init() { lcd_wcom(0x38); // 8-bit data, 2 lines, 5x7 dot matrix lcd_wcom(0x0c); // Display on, cursor off, blink off lcd_wcom(0x06); // Auto increment mode lcd_wcom(0x01); // Clear screen } void lcd_xianshi() { lcd_wcom(0x80 + 0x40); lcd_wdat('D'); lcd_wdat('i'); lcd_wdat('s'); lcd_wdat('t'); lcd_wdat('a'); lcd_wdat('n'); lcd_wdat('c'); lcd_wdat('e'); lcd_wdat(':'); lcd_wcom(0x80 + 0x4c); lcd_wdat('.'); lcd_wcom(0x80 + 0x4e); // Unit: cm lcd_wdat('c'); lcd_wdat('m'); } void init_t0() { TMOD = 0x01; // Timer 0 in mode 1 TL0 = 0x66; TH0 = 0xfc; // 1ms ET0 = 1; EA = 1; } void trigger() { trig = 0; _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); trig = 1; } void init_measuring() { trig = 1; echo = 1; count = 0; } void measuring() { uchar l; uint h, y; TR0 = 1; while(echo == 1) {} TR0 = 0; l = TL0; h = TH0; y = (h << 8) | l; y = y - 0xfc66; // Convert to microseconds distance = y + 1000 * count; // Total time in microseconds TL0 = 0x66; TH0 = 0xfc; delayt(30); distance = 3453 * distance / 20000; // Calculate distance in cm } void display(uint x) { uchar qian, bai, shi, ge; qian = x / 1000; bai = x / 100; shi = x / 10; ge = x; lcd_wcom(0x80 + 0x49); lcd_wdat(table[qian]); lcd_wdat(table[bai]); lcd_wdat(table[shi]); lcd_wcom(0x80 + 0x4d); lcd_wdat(table[ge]); } void main() { lcd_init(); init_t0(); init_measuring(); while(1) { lcd_xianshi(); trigger(); while(echo == 0) {} measuring(); display(distance); init_measuring(); delayt(600); } } // Interrupt service function void T_0() interrupt 1 { TF0 = 0; TL0 = 0x66; TH0 = 0xfc; count++; if(count == 18) { TR0 = 0; TL0 = 0x66; TH0 = 0xfc; count = 0; } }

Low Voltage Lithium Battery

Low-voltage lithium batteries for energy storage

Low-voltage lithium batteries are becoming more and more popular for energy storage. These batteries have a number of advantages over traditional lead-acid batteries, including longer life, smaller size, and lower weight.

1. Introduction to low-voltage lithium batteries

Lithium ion batteries are a type of rechargeable Battery that use lithium ions to store energy. They have a high energy density, making them ideal for portable devices. Low-voltage lithium ion batteries are a type of lithium ion battery that have a reduced voltage. This makes them safer for use in devices that are not safety-rated for high voltages.

2. Applications of low-voltage lithium batteries for energy storage

Low-voltage lithium batteries are finding an increasing number of applications in the energy storage sector. Their high energy density and long cycle life make them well-suited for use in grid-scale storage systems, while their relatively low cost and easy installation make them attractive for use in small-scale applications such as home energy storage systems.

Low-voltage lithium batteries are also being explored as a potential storage solution for renewable energy sources such as solar and wind power. By storing energy from these sources when it is available and releasing it when needed, low-voltage lithium batteries can help to smooth out the peaks and valleys in renewable energy output, making these sources more reliable and efficient.

Low-voltage lithium batteries are the future of energy storage. They are smaller, lighter, and longer lasting than traditional lead-acid batteries, making them perfect for a wide range of applications.

Lithium Iron Phosphate (LiFePO4),Rechargeable Batteries,Low Self-Discharge,Energy Density,Battery Management System (BMS)

Wuxi Sunket New Energy Technology Co.,Ltd , https://www.sunketsolar.com

Posted on