最近搞得課程設計,限於才能有限,只能搞個超聲播測距報警和加舵機繼電器玩了。具體**入下。
#include
#include
#include"lcd.h"
sbit pwm = p0^7;
sbit trig = p0^1;
sbit echo = p0^0;
sbit beep=p1^5;
sbit dianji=p3^7;
sbit irin=p3^2;
typedef unsigned char u8;
typedef unsigned int u16;
unsigned char code ascii[15] = ;
unsigned int pwm; //pwm占空比為50%,可調占空比
unsigned int t = 0;
static unsigned char disnum = 0; //顯示用指標
unsigned int time=0;
unsigned long s=0;
bit flag =0;
unsigned char disbuff[4] =;
u8 irvalue[6];
u8 t;
void delay(unsigned int v)
//初始化紅外置收
void irinit()
void conut(void)
else
}void zd0() interrupt 1 //t0中斷用來計數器溢位,超過測距範圍
void startmodule() //啟動模組
void delayms(unsigned int ms)}}
void timer1init() }
void timer1() interrupt 3
else
if(irvalue[2]==0x40)
if(irvalue[2]==0x43)
}void readlr() interrupt 0
if(irin==1)
for(k=0;k<4;k++)
err=500;
while((irin==1)&&(err>0))
}irvalue[k]>>=1;
if(t>8)
t=0;
}} if(irvalue[2]!=~irvalue[3])
}}
51微控制器超聲波測距
echo是p3.2 trig是p3.7 外部中斷是p3.2 原始碼 include define uint unsigned int void reset 初始化函式 void chufa 觸發訊號函式 void open 等待返回訊號,有訊號開啟定時器 int seven 測量七次並排序 void...
超聲波感測器測距報警器
hc sr04超聲波測距模組 lcd 蜂鳴器 qmc5883l電子羅盤模組 步進機 可無 position.c qmc5883l電子羅盤模組 include lcd.h extern uchar buf 8 資料快取 延時5us void delay 5us 起始訊號 void qmc5883 st...
求助51微控制器超聲波測距
stc89c52rc晶元,hc sr04超聲波測距模組 如下 include include oled.h include hc sr04.h include timer.h include sbit beep p1 5 unsigned char s unsigned long time 0 時間...