超声测距源程序

  • 名称:超声测距源程序
  • 类型:单片机学习
  • 授权方式:免费版
  • 更新时间:09-10 23:00:40
  • 下载要求:无需注册
  • 下载次数:6322
  • 语言简体中文
  • 大小:876 KB
  • 推荐度:3 星级
《超声测距源程序》简介

标签:单片机开发,单片机原理,
超声测距源程序,超声测距c程序免费下载
目录如下:

#include<reg51.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char

sbit dula=P2^7;
sbit wela=P2^6; //数码管段,位定义
sbit send=P1^0; //发送端定义


uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71}; //段码数组


uchar a1,a2,a3; //显示数组;
uint count,b;



void delay(uint a) //延时;
{
uint m;
for(m=0;m<a;m++);
}

void tx() //从P1.0发出40KHz的脉冲
{
uchar n,p;
for(n=0;n<40;n++)
{
send=1;
for(p=0;p<3;p++);
send=0;
for(p=0;p<2;p++);
send=0;
}
}

void display(uchar bai,uchar shi,uchar ge) //显示子函数 字串9
{
for(;;)
{
dula=1;
P0=table[bai];
dula=0;
wela=1;
P0=0x0d;
wela=0;
delay(10);

dula=1;
P0=table[shi];
dula=0;
wela=1;
P0=0x0b;
wela=0;
delay(10);

dula=1;
P0=table[ge];
dula=0;
wela=1;
P0=0x07;
wela=0;
delay(10);
}
}


void rx() interrupt 0 //外部中断0,接收信号并处理
{
TR0=0;
count=TH0*256+TL0;
if(count<55);
if(count>=55)
{
b=(17*count)/1000;
a1=b/100;
a2=b%100/10;
a3=b%100%10;
display(a1,a2,a3);
}
}

void over()interrupt 1 //T0溢出为无效测量,中断显示FFF;
{
a1=table[15];
a2=table[15];
a3=table[15];
display(a1,a2,a3);
}

void main()
{
send=0;
delay(8600); //发射延时 8.6ms?
TH0=0;
TL0=0;
TMOD=0x01; //对定时器0设初值,模式1的16位计数
TR0=1; //开启定时器0 字串9
EA=1;
ET0=1;
PT0=1; //开启定时器0中断并设为高优先级
tx(); //调用发射子函数
IT0=1; // 外部中断0用低电平触发方式
IE=0x83; //设置中断控制,其中开启外部中断0
} 字串9

, 大小:876 KB
Tag:单片机学习单片机开发,单片机原理单片机学习

《超声测距源程序》相关下载