C语言程序解释 麻烦下面这个程序 每个命令命令解释 用// 在后面注释一下 非常感谢
#include<DS89C4xx.h>#include<stdlib.h>#include<stdio.h>#include<absacc.h>#include<str...
#include <DS89C4xx.h>
#include <stdlib.h>
#include <stdio.h>
#include <absacc.h>
#include <string.h>
#define BYTE unsigned char;
sbit trigger= P1^5;
sbit echo=P1^4;
int distance;
void initializion(void)
{
SCON1=0x52; //init for 9600baud rate 8bit data no parity
TMOD=0x21; // timer1, mode2
TH1=0xfd; //baud rate=9600
TR1=1; //start timer1
}
void tx1(unsigned char c)
{
while(TI_1==0);
TI_1=0;
SBUF1=c;
}
void start_trigger(void)
{
int i;
trigger =0;
for( i=0;i<10;i++) trigger=1;
trigger=0;
}
void delay(int time)
{
int i,j;
for(i=0;i<time;i++);
for(j=0;j<2000;j++);
}
void sensor(void)
{
long count;
float time_taken;
count=0;
start_trigger();
while(echo=0);
while(echo==1);
{
count=count+1;
}
time_taken=count*1.085; // one count is 1.085us thru datasheet
distance=time_taken/58.0; // convert to cm
delay(200);
}
void main(void)
{
int i;
BYTE xdata s[50];
i=0;
initializion();
while(1)
{
sensor();
sprintf(s,"%dcm\r", distance); //display in hyperterminal
for(i=0;i<strlen(s);i++)tx1(s[i]);
tx1(0x0a);
tx1(0x0d);
}
}
传送至 519447563@qq.com
谢谢 展开
#include <stdlib.h>
#include <stdio.h>
#include <absacc.h>
#include <string.h>
#define BYTE unsigned char;
sbit trigger= P1^5;
sbit echo=P1^4;
int distance;
void initializion(void)
{
SCON1=0x52; //init for 9600baud rate 8bit data no parity
TMOD=0x21; // timer1, mode2
TH1=0xfd; //baud rate=9600
TR1=1; //start timer1
}
void tx1(unsigned char c)
{
while(TI_1==0);
TI_1=0;
SBUF1=c;
}
void start_trigger(void)
{
int i;
trigger =0;
for( i=0;i<10;i++) trigger=1;
trigger=0;
}
void delay(int time)
{
int i,j;
for(i=0;i<time;i++);
for(j=0;j<2000;j++);
}
void sensor(void)
{
long count;
float time_taken;
count=0;
start_trigger();
while(echo=0);
while(echo==1);
{
count=count+1;
}
time_taken=count*1.085; // one count is 1.085us thru datasheet
distance=time_taken/58.0; // convert to cm
delay(200);
}
void main(void)
{
int i;
BYTE xdata s[50];
i=0;
initializion();
while(1)
{
sensor();
sprintf(s,"%dcm\r", distance); //display in hyperterminal
for(i=0;i<strlen(s);i++)tx1(s[i]);
tx1(0x0a);
tx1(0x0d);
}
}
传送至 519447563@qq.com
谢谢 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询