i used the moisture sensor SN - M114 for my irrigation project..
then i have used the adc (potentiometer) programming.
the programming are working but it doesnt show the value of my sensor.
need help about the programming...
nina aem WROTE:i used the moisture sensor SN - M114 for my irrigation project..
then i have used the adc (potentiometer) programming.
the programming are working but it doesnt show the value of my sensor.
need help about the programming...
//==========================================================================
// include
//==========================================================================
#include <htc.h>
#include "lcd.h"
#include "adc.h"
#include "system.h"
// global variable
//===========================================================================
void delay_ms(unsigned int ui_value);
// Configuration
//==========================================================================
__CONFIG(LVP_OFF&BOREN_OFF&FOSC_INTRC_CLKOUT&WDTE_OFF&PWRTE_ON);
// main function
//==========================================================================
void main(void)
{
PORTA = 0; // clear PORT
PORTB = 0;
PORTC = 0;
PORTD = 0;
TRISA = 0b11111111; // set PORTA as INPUT
TRISB = 0b00000011; // set PORTB<7:2> AS OUTPUT , PORTB<1:0> as INPUT
TRISC = 0b00000000;
TRISD = 0b00000000; // set PORTD as output
ANS2 = 0; // RA2 as DIGITAL I/O
ANSELH = 0; // set PORTB as DIGITAL I/O for PIC16F887
lcd_initialize(); // Initialise LCD
adc_initialize(); // Initialise ADC
unsigned char mode = 1;
while (1) // Loop forever
{
switch(mode)
{
case 1: lcd_clear();
lcd_home();
lcd_putstr("MOISTURE");
delay_ms(1000);
if (SW1 == 1)
{
lcd_clear();
lcd_home();
lcd_putstr("ADC :"); // Put "ADC:" on LDC screen
while (SW1 == 1)
{
unsigned int adc_value = 0;
unsigned char i;
CHS2 = 0; // select ADC channel AN0
CHS1 = 0;
CHS0 = 0;
adc_on(); // ON ADC
for(i = 0 ; i < 10 ; i++)
{
adc_value = adc_value + ui_adc_read(); // take the value for 10 times
}
adc_value = adc_value/10; // Devide the final value by 10 to get the average result
lcd_goto(0x05);
lcd_bcd(4,adc_value); // display on LCD with 4 digit number maximun.
[b]/*if (adc_value == 0<=adc_value<=300)
{
Relay1 = 0;
delay_ms(39);
}
else
{
Relay1 = 1;
}
*/
}
}
}
/*******************************************************************************
* PRIVATE FUNCTION: delay_ms
*
* PARAMETERS:
* ~ ui_value - The period for the delay in miliseconds.
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Delay in miliseconds.
*
*******************************************************************************/
void delay_ms(unsigned int ui_value)
{
while (ui_value-- > 0) {
__delay_ms(1); // macro from HI-TECH compiler which will generate 1ms delay base on value of _XTAL_FREQ in system.h
}
}
Users browsing this forum: No registered users and 24 guests