PIC Vietnam

Go Back   PIC Vietnam > Mua bán & Trao đổi > Tìm mua sản phẩm

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

Tìm mua sản phẩm Muốn tìm một sản phẩm điện tử, hay một linh kiện điện tử bất kỳ, hãy hỏi thành viên của picvietnam

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 07-12-2007, 11:21 AM   #11
seraph
Đệ tử 4 túi
 
Tham gia ngày: Mar 2007
Bài gửi: 62
:
Hic!anh F ơi!em mua con SRF05 ở cty anh rồi,nhưng sao em phát xung 10uS vào chân trigger mà chờ mãi ko thấy Echo phản hồi,không biết nó có hư rùi không.Đây là đoạn code của em,anh coi thử nhé:

#include <18F4550.h>
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP,NOCPD,NOWRT, NODEBUG
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7)
#use fast_io(B)
#use fast_io(D)
#define TRIGGER PIN_B1
#define ECHO PIN_B0

#bit TMR3ON=53.0
#bit TMR3IF=54.1
#byte TMR3H=53
#byte TMR3L=53
#byte T3CON=53

void main()
{
delay_ms(1000);
delay_ms(1000);
delay_ms(1000);
set_tris_b(0x01);
set_tris_d(0x00);
output_high(PIN_D1);//led de test
delay_ms(1000);
output_low(PIN_D1);
delay_ms(1000);
while(1)
{
output_high(PIN_B1);//start trigger
delay_us(10);
output_low(PIN_B1);//stop trigger
TMR3H=0;
TMR3L=0;
T3CON=0x30;//prescale 8:1
TMR3IF=0;
while(!input(PIN_B0)&&!TMR3IF); //wait Echo pulse to start
TMR3ON=1; //start timer3
//output_high(PIN_D1);
while(!ECHO&&!TMR3IF); //wait Echo pulse to stop=> nó bị ở chỗ này(vòng lặp vô tận)
TMR3ON=0;
output_high(PIN_D1);//=>led ko sáng
if(!TMR3IF)
{
output_high(PIN_D1);
delay_ms(500);
output_low(PIN_D1);
}
delay_ms(1000);
}
}
seraph vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 05:42 AM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam