View Single Post
Old 06-05-2012, 10:50 PM   #1
binhcddt09b
Nhập môn đệ tử
 
Tham gia ngày: Jul 2011
Bài gửi: 2
:
nhờ mấy anh giúp em code cảm biến srf04

em có code này viết cho cảm biến siêu âm,nhưng giá trị đọc về từ cảm biến nó chỉ giữ nguyên chứ ko chuyển đổi j khi em di chuyển cảm biến, các bác giúp em sử nó với.mà mỗi đoạn code em coi thì nó lại có một cách chia giá trị khác nhau,em ko biết nên chia ntn nên em lấy trong datasheet luôn.
#include <16f887.h>
#FUSES,nowdt,noprotect,nolvp,put
#use delay(clock=20000000)
#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)
#byte porta=0x5
#byte portc=0x7
#byte portd=0x8
#byte portb=0x6
#byte porte=0x9
#bit c3=portc.3
#include <lcd.c>
float kc=0;

#INT_CCP1
void ccp1_isr()
{
set_timer1(0); //Cai gia tri cho Timer1
setup_ccp1(CCP_CAPTURE_FE); //chuyen sang do canh xuong
kc=(get_timer1())/58;

}

void hienthi(int16 )
{
lcd_gotoxy(1,1);
printf(lcd_putc,"CACH VAT:%f",kc);
lcd_gotoxy(14,1);
Printf(LCD_putc,"cm");
lcd_gotoxy(2,2);
lcd_putc("ROBOT TU HANH");
delay_ms(30);
}
void main()
{
LCD_init();
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
setup_ccp1(CCP_CAPTURE_RE);
enable_interrupts(INT_CCP1); // Cho phép ng?t khi CCP1 có tín hi?u
enable_interrupts(GLOBAL);
//---hien thi LCD---

while(TRUE) {
set_tris_c(0x04);
c3 = 1; //trigger
delay_us(10);
c3 = 0;
hienthi(kc);
delay_ms(50);
}
}
binhcddt09b vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn