วันพฤหัสบดีที่ 7 กุมภาพันธ์ พ.ศ. 2562

งานที่14 Heart Beat Monitoring using PIC Microcontroller and Pulse Sensor


อุปกรณ์

  1. PIC16F877A microcontroller
  2. 20 Mhz Crystal
  3. 33pF capacitor 2 pcs
  4. 4.7k resistor 1 pcs
  5. 16x2 Character LCD
  6. 10K pot for contrast control of the LCD
  7. SEN-11574 Pulse sensor
  8. Velcro strap
  9. 5V Power adapter
  10. Breadboard and hookup wires

code

void main() {
    system_init();
    main_state = READ_ADC;      
    while (1) {
        switch (main_state) {
            case READ_ADC:
            {                
                adc_value = ADC_Read(0); // 0 is the channel number
                main_state = CALCULATE_HEART_BEAT;                
                break;
            }
            case CALCULATE_HEART_BEAT:
            {
                calculate_heart_beat(adc_value);
                main_state = SHOW_HEART_BEAT;
                break;
            }
            case SHOW_HEART_BEAT:
            {
                if (QS == true) { // A Heartbeat Was Found
                    // BPM and IBI have been Determined
                    // Quantified Self "QS" true when Arduino finds a heartbeat                    
                    QS = false; // reset the Quantified Self flag for next time

                    // 0.9 used for getting better data. actually should not be used
                    BPM = BPM * 0.9;
                    IBI = IBI / 0.9;
                    lcd_com(0x80);
                    lcd_puts("BPM:-     ");
                    lcd_print_number(BPM);
                    lcd_com(0xC0);
                    lcd_puts("I.B.I:-   ");
                    lcd_print_number(IBI);                    
                }
            }
                main_state = IDLE;
                break;
       
        case IDLE:
        {            
            break;
        }
        default:
        {

        }
    }
}
}
อ้างอิง

ไม่มีความคิดเห็น:

แสดงความคิดเห็น