اطلاعیه

Collapse
No announcement yet.

برنامه نویسی سنسور رطوبت

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    برنامه نویسی سنسور رطوبت

    سلام دوستان :smile: :smile:
    برنامه ای به زیان c می خوام ...که میزان رطوبت رو از سنسور بگیره در lcd نمایش بده...اگر از یک میزانی بیشتر بود ،یکی از طبقات روشن شود..واگر از یک میزانی کمتر بود،یکی دیگر از طبقات روشن بشه.....
    طراحی مدارشو انجام دادم تو برنامش مشگل دارم....ممنون میشم اگه کسی بلد هست کمکم کنه..

    #2
    پاسخ : برنامه نویسی سنسور رطوبت

    با سلام

    کد:
    #include <mega8.h>
    #include <delay.h>
    #include <stdio.h>
    
    // Alphanumeric LCD Module functions
    #include <alcd.h>
    
    long int timer0_ov;
    long int in_freq;
    char buff[16],buff2[16]; 
    int humidity;
    
    // Timer 0 overflow interrupt service routine
    interrupt [TIM0_OVF] void timer0_ovf_isr(void)
    {
    timer0_ov++;
    
    }
    
    void main(void)
    {
    
    	TCCR0=0x06;
    	TCNT0=0x00;
    	TIMSK=0x01;
    
    	// Alphanumeric LCD initialization
    	// Connections specified in the
    	// Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
    	// RS - PORTB Bit 0
    	// RD - PORTB Bit 1
    	// EN - PORTB Bit 2
    	// D4 - PORTB Bit 4
    	// D5 - PORTB Bit 5
    	// D6 - PORTB Bit 6
    	// D7 - PORTB Bit 7
    	// Characters/line: 16
    	lcd_init(16);
    
    	// Global enable interrupts
    	#asm("sei")
    
    	while (1)
    	{ 
    		TCCR0=0x06;
    		#asm("sei")
    		delay_ms(50);
    		#asm("cli")
    		in_freq=20*(timer0_ov*256+TCNT0);
    		sprintf(buff,"Freq=%d",in_freq);
    		//delay_ms(250);
    		lcd_clear();
    		lcd_puts(buff);
    		TCCR0=0x00;
    		timer0_ov=0;
    		TCNT0=0;  
    
    		humidity=(-0.075872)*(in_freq-7351);
    		lcd_gotoxy(0,1);
    		sprintf(buff2,"Humidity=%d",humidity);
    		lcd_puts(buff2);
    	}
    }
    شماتیک :
    http://www.4shared.com/photo/nWgAVDW..._rotoobat.html

    دیدگاه

    لطفا صبر کنید...
    X