You are on page 1of 2

http://www.mikroe.com/forum/viewtopic.php?

f=88&t=26439&view=next

* Test configuration:
MCU: PIC16F887
Dev.Board: PICkit 3
Oscillator: HS, 10.0000 MHz
Ext. Modules: -
*/

#define Saline_status PORTC.F4

void Delay_ms(const time_in_ms);

void main() {
double ECG,ECG0,ECG1,ECG2,ECG3 ;

int HEARTRATE, RESP_TEMP, VOLTAGE2 ,BODY_TEMP ,CALL,VOLTAGE1; int


cardreadresult ,ON=1,CHANGE=1,OK=0;
char Patient_calling = 'a',CARDREADER='b', ECG_S = 'c',
BODY_TEMPERATURE='d',RESPIRATORY_TEMPERATURE = 'h';
char SALINE_SATUS = 'g',HEARTRATE_SENSOR = 'f' ;
unsigned short pulserate, pulsecount ;
unsigned long Vin ,ECG4, ECG5 ;

ADCON1 = 0x80; // Configure AN0-6 pins as analogue


TRISA = 0xFF; // set direction to be input
TRISB = 0xFF; // set direction to be input
TRISC = 0xFF; // set direction to be input
TRISD = 0xFF; // set direction to be input
Uart1_Init(9600); // initialise uart1

for(; ;) {

CALL = PORTD ; // Patient_calling SWITCHES


Uart1_Write(Patient_calling);
Delay_ms(1);
if (CALL> 0x00) {
Uart1_Write( ON);
}

cardreadresult = PORTB ; //CARDREADER


Uart1_Write(CARDREADER);
Delay_ms(1);
if (cardreadresult > 0x00) { //send cardreadresult to usart
Uart1_Write(cardreadresult);
}

//ECG SENSOR
ECG0 = Adc_Read(0); // Read from channel 0 (AN0)
Delay_ms(1); //One msecond pause
ECG1 = Adc_Read(1); // Read from channel 1 (AN1)
Delay_ms(1); //One msecond pause
ECG2 = Adc_Read(2); // Read from channel 2 (AN2)
Delay_ms(1); //One msecond pause
ECG3 = Adc_Read(3); // Read from channel 3 (AN3)
Delay_ms(1); //One second pause
ECG4 = (ECG0 + ECG1 + ECG2 + ECG3)/4 ;
ECG5 = ECG4*100 ; // Scale up the result
ECG = ECG5 / 8192 ; // Convert to mV
Uart1_Write(ECG_S) ;
Delay_ms(1);

1
Uart1_Write(ECG) ;

VOLTAGE1 = Adc_Read(5); // BODY TEMPERATURE


Uart1_Write(BODY_TEMPERATURE);
Vin = 488*VOLTAGE1; // Scale up the result
BODY_TEMP = Vin /100; // Convert to temperature in C
Delay_ms(1);
Uart1_Write(BODY_TEMP);

VOLTAGE2= Adc_Read(6); // RESPIRATORY TEMP SENSOR


Uart1_Write(RESPIRATORY_TEMPERATURE);
Delay_ms(1);
Vin = 488*VOLTAGE2; // Scale up the result
RESP_TEMP = Vin /100; // Convert to temperature in C
Uart1_Write(RESP_TEMP);

Uart1_Write(SALINE_SATUS); //SALINE SATUS


Delay_ms(1);
if (Saline_status == 1 ){
Uart1_Write(CHANGE);
} //send change saline status signal to uart
else{
Uart1_Write(OK); // SALINE STATUS OK
}

TMR0=0; // Heart rate sensor to counter


Delay_ms(10000); // Delay 10 Sec
pulsecount = TMR0;
HEARTRATE = pulsecount*6;
Uart1_Write(HEARTRATE_SENSOR);
Delay_ms(1);
Uart1_Write(HEARTRATE);

} // Endless loop
}

You might also like