Which master has 51 SCM ultrasonic module ranging LCD1602 display C program
Author:Typhoon shelter Time:2021-07-19 13:36 Browse(377)
1602 LCD
1602 LCD ultrasonic module program.
interface program has,,.

Which master has 51 SCM ultrasonic module ranging LCD1602 display C program

.
? Include & lt; reg52.h>.
//#include< delay.h>.
#include < intrins.h>.
.
#define uchar unsigned char.
#define uint unsigned int.
.
sbit lcdrs=P2^3;.
sbit lcden=P2^2;.
sbit trig=P2^0; //
/ / sbit echo=P3 ^ 2// Ultrasound was accepted.
/ / P 0____________ DB0-DB7.
uchar dis[]="Disp_ HC-SR04";.
uchar num[]="0123456789";.
uint distance;.
.
void delay(uint z).
{.
uint x.
y;.
for(x=z; x> 0; x--).
for(y=121; y> 0; y--);.
}.
.
void HC_ init().
{.
TMOD=0x09;.
TR0=1;.
TH0=0; TL0=0;.
}.
.
uint HC_ jisuan().
{.
uint dist.
timer;.
timer=TH0;.
timer<& lt;=8;.
timer=timer|TL0;.
dist=timer/53; // Crystal oscillator 11.0592Mhz, distance cm=microsecond US / 58.
return dist// One machine cycle is 12 clock cycles, timer * 12 / (58 * 11.0592)=timer / 53.
}.
.
void HC_ run().
{.
uint tempH=0x00.
tempL=0x00;.
TH0=0; TL0=0;.
trig=0;.
trig=1;.
delay(1);.
trig=0;.
while((TH0-tempH!=0||TL0-tempL!=0)||(TH0==0&& amp; TL0==0)).
{.
tempH=TH0;.
tempL=TL0;.
}.
delay(1);.
}.
void lcd_ write_ Com (uchar com) / / LCD write instruction.
{.
lcdrs=0
P0=com;.
delay(1);.
lcden=1;.
delay(1);.
lcden=0;.
}.
.
void lcd_ write_ Data (uchar date) / / LCD writes data.
{.
lcdrs=1
P0=date;.
delay(1);.
lcden=1;.
delay(1);.
lcden=0;.
}.
.
void lcd_ Init() / / LCD initialization.
{.
lcden=0
lcd_ write_ com(0x38);.
lcd_ write_ com(0x0c);.
lcd_ write_ com(0x06);.
lcd_ write_ com(0x01);.
}.
.
void lcd_ display(uchar temp).
{.
uint i;.
.
lcd_ write_ com(0x82);.
for(i=0; i< 12; i++).
{.
lcd_ write_ data(dis[i]);.
}.
.
lcd_ write_ com(0x80+0x41);.
lcd_ write_ data('D');.
lcd_ write_ data('i');.
lcd_ write_ data('s');.
lcd_ write_ data('t');.
lcd_ write_ data('a');.
lcd_ write_ data('n');.
lcd_ write_ data('c');.
lcd_ write_ data('e');.
lcd_ write_ data(':');.
lcd_ write_ data(num[temp/100]);.
lcd_ write_ data(num[temp/10%10]);.
lcd_ write_ data(num[temp%10]);.
lcd_ write_ data('c');.
lcd_ write_ data('m'); .
}.
.
void main().
{.
lcd_ init();.
HC_ init();.
while(1).
{.
HC_ run();.
distance=HC_ jisuan();.
lcd_ display(distance);.
delay(200);.
}.
}.
.
.
Related topics