本帖最后由 liyanxiandai 于 2016-4-10 09:21 编辑
超声测距模块电路:
EM78P153 超声波测距原代码
;**********************************
;超声波模块程序
;**********************************
;P50/-trigger-[ ]-P51/ ir_out2
;P67/-echo -[ ]-P52/ ir_out1
;P66/ -[ ]-P53/ tx_power_control
;VDD -[ ]-VSS
;P65/ -[ ]-P60/ signal_in
;P64/ -[ ]-P61/ comparator control
;P63/ -[ ]-P62
include "EM78P153S.INC"
p5 == 0X05
p6 == 0X06
trigger == p5.0
ir_out2 == p5.1
ir_out1 == p5.2
tx_power == p5.3
signal == p6.0
compa == p6.1
echo == p6.7
a_buffer == 0x10
r3_buffer == 0x11
R4_buffer == 0x12
t_24ms_reg == 0x13
t_48ms_reg == 0x14
t_192ms_reg == 0x15
tim_flag == 0x16
s_12ms == 0x16.0
s_24ms == 0x16.1
s_48ms == 0x16.2
s_192ms == 0x16.3
count0 == 0X17;延时寄存器1
count1 == 0X18;延时寄存器2
/*************************************/
org 0x00
jmp start
org 0x08
jmp tcc_int
/***********初始化****************/
start:
call initial ;IO及寄存器初始化
/***********等外部触发脉冲****************/
loop: bc echo
jbs p5,0
jmp loop ;等待外部10微秒以上的触发脉冲
lop1: nop
jbc p5,0
jmp lop1 ;触发脉冲结束
/************超声波发射***************/
bc p5,3 ;给超声波发射忒片MAX232供电
call dely_250us;延时250 US
call irlop ;发射超声波
bs p5,3 ;发射结束,关超声发射电源
bc p6,1 ;比较器反向输入端置低电平
call dely_118us;延时118US,避开2cm内盲区
bs echo ;echo口置高电平
/************检测回波***************/
lop2: jbc p6,0 ;检测signal_in是否为低,以至判断超声回波
jmp lop_high
call dely_250us
jbc p6,0
jmp lop_high
lop_low:
bc echo ;收到回波
jmp start
lop_high:
jbs p6,0
jmp lop2
jbs s_24ms
jmp lop_high
bc s_24ms ;超过4M,作无效处理
lop_h2:
jbc p5,0
jmp lop_h2
jmp loop
;============================================
;时间中断
;============================================
tcc_int:
mov a_buffer,a
mov a,r3
mov r3_buffer,a
mov a,@69 ;TCC overflow time = (1/4MHz)*(256-69)*256=12ms
mov tcc,a
bs s_12ms
dec t_24ms_reg
jbs z
jmp int_ret
mov a,@2;
mov t_24ms_reg,a
bs s_24ms
int_ret:
mov a,iocf
and a,@0xfe
mov iocf,a
mov a,r3_buffer
mov r3,a
swap a_buffer
swapa a_buffer
reti
/**初始化********************/
initial:
mov a,@0b00001001
mov port5,a
mov a,@0b00000001
iow ioc5
mov a,@0b00001010 ;初始P61为高电平
mov port6,a
mov a,@0b00001001 ;设定P60为输入/61为输出口
iow ioc6
mov a,@0b11111111
iow iocb ;P6口下拉关
mov a,@0b10000010 ;P61,67漏极开路输出使能
iow iocc
mov a,@0b10000001
iow iocd ;P60口关上拉
mov a,@0b00000111
contw
clra
iow ioce
mov a,@0b00000111
contw
mov a,@69 ;TCC overflow time = (1/4MHz)*(256-69)*256=400u12ms
mov tcc,a
clr isr ;清除中断标志
mov a,@0b00000001
iow imr ;使能TCC中断功能
mov a,@2;
mov t_24ms_reg,a
mov t_48ms_reg,a
mov a,@0
mov count0,a
mov count1,a
mov a_buffer,a
mov r3_buffer,a
mov r4_buffer,a
mov tim_flag,a
ret
/**(13.3*2)=38KHZ 发38KHZ红外波**********/
irlop:
bs p5,2
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
bc p5,2
bs p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
bs p5,2
bc p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;====================
bc p5,2
bs p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;====================
bs p5,2
bc p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;====================
bc p5,2
bs p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;====================
bs p5,2
bc p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;====================
bc p5,2
bs p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;====================
bs p5,2
bc p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;====================
bc p5,2
bs p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
bs p5,2
bc p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;====================
bc p5,2
bs p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;====================
bs p5,2
bc p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;====================
bc p5,2
bs p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;====================
bs p5,2
bc p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;====================
bc p5,2
bs p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;====================
bc p5,1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
ret
/**延时***************/
dely_118us:
mov a,@3
mov count0,a
delay_xus:
mov a,@10
mov count1,a
delay_b:
nop
nop
nop
djz count1
jmp delay_b
djz count0
jmp delay_xus
ret
dely_250us:
mov a,@5
mov count0,a
delay_nus:
mov a,@10
mov count1,a
delay_a:
nop
nop
nop
djz count1
jmp delay_a
djz count0
jmp delay_nus
ret
/**********************/
END
153芯片为一个微控制器用于控制超声波信号的发送和探测超声波信号。MAX232芯片为单电源电平转换芯片用来压驱动超声波探头。TL074芯片是一个低噪声运放,用来放大接收信号。工作过程:当Tirg收到一个宽度超过10uS的高脉冲后,153芯片控制P53脚置低,然后通过P51和P52脚输出40KHz脉冲信号,该信号通过MAX232放大后驱动超声波探头发出超声波,信号发送完成后将P67置高,P61脚置低,等待回波。当超声波接收探头接受到回波后,接收放大电路便输出放大后的接收信号到TL074的第一通道同相输入口,Q2导通,P60此时变为低,153检测到这个变化便将Echo脚置低,表示接受到了回波。Echo口的高电平持续时间即为超声波发送到接收的延迟时间,通过单片机定时器测量这个时间,即可算出被测物和探头之间的距离. 以上为程序工作过程,可就是不知问提在哪,一点功能都没有,断断续续弄了近一个月,就是不知问提在哪,都说做技术的不怕麻烦,就怕不知如何下手.路过的高手可否给点提示,很是感谢!可发邮箱:LYXD1815@126.COM,或加Q:1506235145
|