View previous topic :: View next topic |
Author |
Message |
princesse
Joined: 12 Mar 2004 Posts: 1 Location: Minnesota
|
pressure sensor MPX4115A |
Posted: Mon Sep 27, 2004 10:04 pm |
|
|
Does any one have a code for the programming of a pressure sensor?...Basically, I am using PIC16F877 and i want to measure the pressure..I am using MPX4115A as the part number of my pressure sensor. Could you please help me out? I tried calibrating my pressure sensor but when i do my testing, the value of the pressure that i see on my LCD is different from whatever the pressure should really be.
I appreciate your help!
Below is the software that I have so far
////////////////////////////////////////////////////////////////////////////////
//This program will read the PRESSURE inside the room and display it on /////
//LCD /////
////////////////////////////////////////////////////////////////////////////////
/////////////read_adc() will read the digital value from the A/D converter//////
#include <16F877.h>
//#device ADC=10
#include <STDLIB.H> //needed because of A to D converter
#use delay (clock = 4000000) //Oxillator speed, using a 4 Mhz clock
#define RS Pin_E0
#define E Pin_E1
#define A1 Pin_A1
#define lines 0x38
#define clear 0x01
#define home 0x02
#define blink 0x0F
void initLCD (void);
void lcd_send_command(int8 command);
void display_A_D(long ad);
void lcd_send_data(int8 m);
void main (void)
{
int16 value;
int num =0;
float press;
long final;
initLCD();
setup_adc( ADC_CLOCK_INTERNAL );
setup_adc_ports( RA0_ANALOG ); //Saying only pin A0 is analog
set_adc_channel(0);
while (true) {
delay_ms( 2000 ); //delay 2 s
value=read_adc(); //read_adc() returns 8 bit digital value
display_A_D(value);
delay_ms( 2000 );
press = ((value*2.8)+445.5);
final = press;
display_A_D(final);
delay_ms( 1000 );
initLCD();
}
}
//Main ends here
void initLCD (void)
{
lcd_send_command(lines);
lcd_send_command(clear);
lcd_send_command(home);
lcd_send_command(blink);
}
void lcd_send_command(int8 command)
{
output_d(command); //send a command to Port D
output_low(RS);
output_high(E);
delay_ms(5); //delay 5ms
output_low(E);
delay_ms(10); //delay 10ms
}
void lcd_send_data(int8 m)
{
output_d(m); //send a temperature value to Port D
output_high(RS);
output_high(E);
delay_ms(5);
output_low(E);
delay_ms(10);
}
void display_A_D(long ad)
{
long lstval,val,getvalue;
lstval=(ad/1000)+0x30; //to get the 1st digit from the A to D value
//putc(lstval); //send the 1st digit to the pc monitor and LCD
lcd_send_data(lstval);
ad=ad%1000;
getvalue=(ad/100)+0x30; //to get the 2nd digit from the A to D value
//putc(getvalue); //send the key to the pc monitor
lcd_send_data(getvalue);
val=ad%100;
getvalue=(val/10)+0x30; //to get the 3rd digit from the A to D value
//putc(getvalue); //send the key to the pc monitor
lcd_send_data(getvalue);
getvalue=(val%10)+0x30; //to get last digit from the A to D value
//putc(getvalue); //send the key to the pc monitor
lcd_send_data(getvalue);
} |
|
|
dvsoft
Joined: 28 Nov 2003 Posts: 46
|
|
Posted: Mon Sep 27, 2004 11:54 pm |
|
|
bonjour,
you write
Code: |
press = ((value*2.8)+445.5);
|
try
Code: |
press = ( (((float)value)*2.8) +445.5);
|
for you LCD
Code: |
void display_A_D(long ad)
{
int8 Index;
char Buffer[16];
sprintf(Buffer, "%4ld", ad);
i = 0;
do {
lcd_send_data(buffer[i]);
} while (++i < 4);
}
|
bon courrage
Alain |
|
|
|