PIC Vietnam

Go Back   PIC Vietnam > Robotics > Cảm biến

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

Cảm biến Camera, siêu âm, hồng ngoại, gyro, la bàn...

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 26-02-2013, 11:06 AM   #2
hungcdt_k49
Đệ tử 1 túi
 
Tham gia ngày: Nov 2012
Bài gửi: 19
:
code nay do em viet nhung no khong chay. Moi nguoi sua giup em voi a
#include <16f877a.h>
#fuses HS,NOWDT,NOLVP,NOPROTECT
#use delay(clock=12000000)
int8 i,j,k,led[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0},dv,chuc,tram;
float time,kc;
#define trig pin_B1
#define echo pin_B0
#int_TIMER1
void trantimer1()
{
set_timer1(0);
}
#INT_EXT
void ngatngoai()
{
if(input(pin_b0)) //neu la xung canh len
{
set_timer1(0);
ext_int_edge(H_to_L);
}
else // neu la xung canh xuong
{
time=get_timer1(); // doc gia tri timer 1
kc=((time*(4*4/12))/58); // tinh khoang cach. moi nhip timer1 ung voi 1.33us
ext_int_edge(L_to_H); // chuyen sang do canh len
disable_interrupts(int_timer1); // khong cho phep ngat timer1
output_a(255);
for(i=0;i<50;i++)
{
dv=(int8)kc%10;
chuc=(int8)(kc/10)%10;
tram=(int8)(kc/100)%10;
output_d(led[dv]);
output_a(0xfe);
delay_ms(1);
output_a(0xfd);
output_d(led[chuc]);
delay_ms(1);
output_a(0xfb);
output_d(led[tram]);
delay_ms(1);
}
}
}
void trigger()
{
output_high(trig);
delay_us(12);
output_low(trig);
}
void main()
{
set_tris_a(0);
set_tris_d(0);
set_tris_b(0);

setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_EXT);
ext_int_edge(L_to_H);
enable_interrupts(global);
while(1)
{
trigger();
delay_ms(50);
}
}
hungcdt_k49 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 

Ðiều Chỉnh
Xếp Bài

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à 06:19 PM.


Đượ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