Merhaba arkadaşlar; bir projeyle uğraşıyorum LM35 ile sıcaklık değerini lcd ekranını alan ve 2 adet mesafe sensörüyle de saydırma işlemi
yapmaya çalışıyorum. Mesafe sensörleri ayrı ayrı çalışıyor, ilk sensör belirlenen mesafeye göre kişi sayısını arttırıyor ikncisi de kişi sayısını
azaltıyor. Sorunum iki mesafe sensörünü beraber kullanmayı başaramadım, ikisi beraber çalışırken sürekli arttırma işlemi yapıyor. Cevaplarınızı bekliyorum,teşekkürler.
#define LCD_RS_PIN PIN_D0
#define LCD_RW_PIN PIN_D1
#define LCD_ENABLE_PIN PIN_D2
#define LCD_DATA4 PIN_D3
#define LCD_DATA5 PIN_D4
#define LCD_DATA6 PIN_D5
#define LCD_DATA7 PIN_D6
//End LCD module connections
#include <16F877A.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#device ADC=10
#use delay(clock = 4MHz)
#include <lcd.c>
#use fast_io(b)
#use fast_io(d)
int sum=0;
char temperature[] = " 00.0 C";
unsigned int16 temp,i,distance;
void main(){
setup_adc(ADC_CLOCK_INTERNAL); // ADC Module uses its internal oscillator
setup_adc_ports(AN0); // Configure AN0 pin as analog
set_adc_channel(0); // Select channel 0 (AN0)
output_b(0);
set_tris_b(0b00000010); //RB1 as a input
set_tris_b(0b00001000); //RB3 as a input
lcd_init(); // Initialize LCD module
setup_timer_1 (T1_INTERNAL | T1_DIV_BY_2);
set_timer1(0);
lcd_putc('\f'); // Clear LCD
lcd_gotoxy(1, 1); // Go to column 1 row 1
printf(lcd_putc, "Temperature:");
//lcd_gotoxy(1, 2);
//lcd_putc("Distance:");
while(TRUE){
delay_ms(1000);
temp = read_adc() * 0.489; // Read analog voltage and convert it to degree celsius (0.489 = 500/1023)
if (temp > 99)
temperature[0] = 1 + 48; // Put 1 (of hundred)
else
temperature[0] = ' '; // Put space
temperature[1] = (temp / 10) % 10 + 48;
temperature[2] = temp % 10 + 48;
temperature[5] = 223; // Degree symbol
lcd_gotoxy(12, 1); // Go to column 5 row 2
printf(lcd_putc, temperature); // Display LM35 temperature result
// distance sensor
i = 0;
output_high(PIN_B0);
delay_us(10);
output_low(PIN_B0);
set_timer1(0);
while(!input(PIN_B1) && (get_timer1() < 1000));
while(input(PIN_B1) && (i < 25000))
i = get_timer1(); // Store Timer1 value in i
distance = (i/58); // Calculate the distance
lcd_gotoxy(1, 2);
if(distance <= 10)
{
sum ++;
}
printf(lcd_putc,"Kisi = %d", sum);
i = 0;
output_high(PIN_B2);
delay_us(10);
output_low(PIN_B2);
set_timer1(0); // Reset Timer1
while(!input(PIN_B3) && (get_timer1() < 1000));
while(input(PIN_B3) && (i < 25000))
i = get_timer1(); // Store Timer1 value in i
distance = (i/58); // Calculate the distance
lcd_gotoxy(1, 2);
if(distance <= 10)
{
sum --;
}
printf(lcd_putc,"Kisi = %d", sum);
}
}