i am doing a project where im taking systole and diastole values. Here systole occurs at 1.6V so in the coding below i a using a 'Press=150' value with decrease loop of 2 per second as per compressor release rate(2mmhg/sec).
now i got to check so that when the 'Voltage' is 1.6V it has to 'serialOutput' that corresponding 'Press' value....
in my coding given below i am getting 'serialOutput'(usart) of 'Press' value in hyperterminal every second, but y concern is that if the above condition satisfies the corresponding 'Press' value should be displayed...
i have pasted y code below....please help me....
Code: Select all
void Init();
void serialOutput(unsigned long int);
void serial_Data(char);
void Delay(unsigned int);
unsigned int i=0,j,l;
unsigned int Pressure,Value,LoValue,HiValue,Press=150;
unsigned char k[10];
void main()
{
Init(); // Initialisation
while(1)
{
ADCON0=0x85; // Configure the A/D control registers
while(ADCON0 & 0x04); //Wait for conversion to complete
LoValue = ADRESL; //Read the low 8 bit value
HiValue = ADRESH; //Read the upper 8 bit value
Value = ( (unsigned int)HiValue << 8 )+ (unsigned int) LoValue; //Load the 10 bit result into Value
Pressure = Value * 150/1023 ; //Scale the value to the range 0.0 - 150.0mmHg
for(;;){
Press=Press-2;
Delay_ms(1000);
if(Pressure=120) //i need help here, this is the systole point that the code catches at 1.6V
serialOutput(Pressure);
if(Pressure=80) //i also need this point as it is mean pressure value; i need help here
serialOutput(Pressure); }
Delay(100); //delay for ADC loop
}
}
void Delay(unsigned int DelayCount)
{
while(--DelayCount);
}
void serial_Data(char i)
{
txreg = i; // assign the value to portc to display
Delay(10000);
}
void serialOutput(unsigned long int i)
{
unsigned char n,s,j=1;
unsigned int m;
m=i; // assign formal argument to other variable
while(m!=0) // check that value is Zero or not
{
s= m-(m/10)*10; //Store the remainder of m/10 in s
k[j]=s; //Move s to an array
j++; //Increment the array address
m=m/10; //Divide the value by 10,store the Quotient in 'm'
}
k[j]='\0'; // assign the NULL value at the end of the array
j=j-1; // decrement the array address
if(k[3] > 0)
{
n=0x30+k[3]; // convert to ascii value
serial_Data(n); // pass that value to display function
}
else serial_Data(0x20); //Print a space if a zero value
n=0x30+k[2]; // convert to ascii value
serial_Data(n); // pass that value to display function
n=0x30+k[1]; // convert to ascii value
serial_Data(n); // pass that value to display function
serial_Data(0x20);
}
void Init()
{
TRISA = 0X01;
TRISB = 0x00;
PORTB = 0x00;
TRISC = 0x80; //RC7 (RX) is input, RC6 (TX) is output
PORTC = 0xFF;
RCSTA = 0X90; //Enable Serial port
TXSTA = 0X20; //Enable Transmit in asynchronous low speed mode
SPBRG = 0X09; //For Baud rate close to 9600 with 6.0MHz clock
ADCON0= 0x85; // Configure the A/D control registers
ADCON1= 0x8E;
PORTB |= 0x20;
PORTB |= 0x10;
PORTA |= 0x08;
PORTA |= 0x20;
}