How to read sensors simultaneously

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

How to read sensors simultaneously

Postby ecah » Thu Jun 27, 2013 12:04 am

Hello..

I need help here.. im try to run my coding which i want to show on lcd. but i dont know how to make a coding so that lcd will show each reading one after another..start with temperature then moisture followed by carbon. but from my coding below,it juz read temperature..totally need your help :(

CODE: SELECT_ALL_CODE
/*
 
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

//  Set VREF according to the voltage reference :
//  5.00 - power supply jumper set to 5V position (reference = 5V)
//  3.30 - power supply jumper set to 3.3V position (reference = 3.3V)
const unsigned short VREF = 5.0;

unsigned int temp_res;
float temp;
int carbon_mono ;
int moist_read;
char txt[15];
int ANCON0 ;                     // Configure PORTB pins as digital
 int ANCON1   ;                   // Configure RE1 pin as analog
 int ANCON2 ;
 int ANSEL3_bit;
 int ANSEL2_bit;
 int ANSEL1_bit;
void main() {
  ANCON0 = 0x00;                      // Configure PORTB pins as digital
  ANCON1 = 0x00;                      // Configure RE1 pin as analog
  ANCON2 = 0x00;
  ANSEL3_bit = 1;
  ANSEL2_bit =1 ;
  ANSEL1_bit=1;
  TRISA3_bit = 1;                     // Configure RA3 pin as input
  TRISA2_bit = 1;
  TRISA1_bit=1;
  ADC_Init();                         // Initialize ADC

  Lcd_Init();                         // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);                // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);           // Cursor off

  Lcd_Out(1, 1, "Temperature :");
  Lcd_Chr(2,8,223);                   // Different LCD displays have different
                                      //   char code for degree
  Lcd_Chr(2,9,'C');                   // Display "C" for Celsius

  temp_res = 0;
  do {
    temp_res = ADC_Get_Sample(3);     // Get 10-bit results of AD conversion
    temp = (temp_res * VREF)/100;  // Calculate temperature in Celsuis
                                      //  change Vref constant according
                                      //  to the power supply voltage
    FloatToStr(temp, txt);            // Convert temperature to string
    txt[4] = 0;
    Lcd_Out(2,3,txt);                 // Write string in second row
    Delay_ms(1000);
  } while(1);

   Lcd_Cmd(_LCD_CLEAR);                // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);           // Cursor off

  Lcd_Out(1, 1, "Carbon Monoxide :");



 carbon_mono = 0;
  do {
   carbon_mono = ADC_Get_Sample(3);     // Get 10-bit results of AD conversion

    FloatToStr(carbon_mono, txt);            // Convert  to string
    txt[4] = 0;
    Lcd_Out(2,3,txt);                 // Write string in second row
    Delay_ms(1000);
  } while(1);
 

   Lcd_Cmd(_LCD_CLEAR);                // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);           // Cursor off

  Lcd_Out(1, 1, "Moisture :");


 moist_read = 0;
  do {
    moist_read = ADC_Get_Sample(3);     // Get 10-bit results of AD conversion
    FloatToStr(moist_read, txt);
    txt[4] = 0;
    Lcd_Out(2,3,txt);                 // Write string in second row
    Delay_ms(1000);
  } while(1);
     }
ecah
Fledgling
 
Posts: 1
Joined: Wed Jun 26, 2013 11:41 pm

Re: How to read sensors simultaneously

Postby robosang » Fri Jun 28, 2013 7:35 am

Don just paste the code here, no one will look at the code, you need to take some photos and point out which part is having problem.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: How to read sensors simultaneously

Postby ABSF » Fri Jun 28, 2013 11:26 am

robosang WROTE:Don just paste the code here, no one will look at the code, you need to take some photos and point out which part is having problem.


Totally agree with robosang.... :mrgreen:

You have spent so much time in your program. And if you have no clue which part is giving you the problem, we would have to spend the same amount of time to understand how your program work too. And no one here can afford that.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 30 guests