回覆列表
  • 1 # 邢州巔峰數碼

    / send time between beats with a /在LCD12864上顯示BPM

    }

    delay(138);9; Set / 傳送並處理原始脈搏感測器資料

    if (QS == true){ //fadeRate Variable to 255 to fade LED with pulse

    sendDataToProcessing(B;Qi++){

    delay(1000);}

    if (Pressure<100){

    beep = 0;}}

    if(BPM<60|BPM>100){

    for(i=0;i<顯示資訊4

    while(1)

    {

    sendDataToProcessing(}

    }

    }

    //AD轉換結果result

    ADC_CONTR&=0xf8; /依次執行寫入操作

    {

    putchar(ucStr3[i]);

    }

    for(i = 0;

    _nop_();/ 延時 19.6ms

    LCD_disp_list_char(4,DisBuff2);設定ADC CONTR控制暫存器後; /S 確定發現一個心跳

    fadeRate = 255,0;/void ledFadeToBeat(){

    //,BPM); /// analogWrite(fadePin,fadeRate); /:GetADCResult

    函式功能:獲取AD轉換結果函式

    入口引數;, Signal);

    sys_init();

    beep = 1;

    LCD12864_DisplayOneLine(0x80,ucStr1); //,255); // prefix

    QS = false; /,IBI),4;/ reset the Quantified Self flag for next time

    LCD_disp_list_char(2:BYTE ch(通道選擇)

    返回值:result(A/ //依次執行寫入操作

    {

    putchar(ucStr2[i]);

    }

    for(i=0、CHS1、CHS0(清除通道選擇)

    _nop_(); //顯示資訊1

    LCD12864_DisplayOneLine(0x90,ucStr2); // keep LED fade value from going into negative numbers!

    /B}

    for(i = 0;i<3;i++)

    {

    putchar(DisBuff[i]);/清除ADC控制暫存器ADC CONTR的CHS2,DisBuff);/16;i++) /和心率

    sendDataToProcessing( set LED fade value

    //,要加4個空操作延時才可以正確讀到ADC CONTR暫存器的值

    _nop_();4;i++) //,4;i++){

    delay(1000);}

    if(BPM<60|BPM>100){

    beep = 0;i<16; /i++) //8;

    }

    for(i = 0;Q/ }

    /******************************************************************************

    函式名稱;顯示資訊2

    LCD12864_DisplayOneLine(0x88,ucStr3); //ledFadeToBeat();顯示資訊3

    LCD12864_DisplayOneLine(0x98,ucStr4); //i<16;}

    for(i = 0;i<

    unsigned int GetADCResult(BYTE ch)

    { unsigned int result; //依次執行寫入操作

    {

    putchar(ucStr1[i]);/ fade LED

    /i<16; fadeRate = constrain(fadeRate;i++) // / 傳送一個 fadeRate -= 15; //D轉換結果)

    備註:無

    *******************************************************************************/

    _nop_();

    ADC_CONTR = ADC_POWER | ADC_SPEEDLL | ch | ADC_START; //開ADC電源,選擇AD轉換速率,並選擇AD通道,開始AD轉換

    _nop_(); //設定ADC CONTR控制暫存器後,要加4個空操作延時才可以正確讀到ADC CONTR暫存器的值

    _nop_();

    _nop_();

    _nop_();

    while (!(ADC_CONTR & ADC_FLAG));//等待AD轉換結束

    ADC_CONTR &= ~ADC_FLAG; //關閉ADC

    result=ADC_RES; //將AD轉換結果的高兩位賦給result

    result=result<<8; //將result迴圈左移8位

    result+=ADC_RESL; //將AD轉換結果的底8位加高兩位共10位給result

    return result; //返回10位AD轉換結果

    }

    void sendDataToProcessing(char symbol, int dat ){

    putchar(symbol); // symbol prefix tells Processing what type of data is coming

    printf("%drn",dat); // the data to send culminating in a carriage return

    }

    void UART_init(void)

    {

    TMOD = 0x20; //定時器工作在定時器1的方式2

    PCON = 0x00; //不倍頻

    SCON = 0x50; //串列埠工作在方式1,並且啟動序列接收

    TH1 = 0xFd; //設定波特率 9600

    TL1 = 0xFd;

    TR1 = 1; //啟動定時器1

    }

    char putchar(unsigned char dat)

    {

    TI=0;

    SBUF=dat;

    while(!TI);

    TI=0;

    return SBUF;

    }

    void _nop_ (void)

    {}

    void T0_init(void){

    // Initializes Timer0 to throw an interrupt every 2mS.

    TMOD |= 0x01; //16bit TIMER

    TL0=T0MS;

    TH0=T0MS>>8;

    TR0=1; //start Timer 0

    ET0=1; //enable Timer Interrupt

    EA=1; // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED

    }

    void T1_init(void){

    // Initializes Timer0 to throw an interrupt every 2mS.

    TMOD |= 0x01; //16bit TIMER

    TL1=T0MS2;

    TH1=T0MS2>>8;

    TR1=1; //start Timer 0

    ET1=1; //enable Timer Interrupt

    EA=1; // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED

    }

    void ADC_init(unsigned char channel)

    {

    P1ASF=ADC_MASK< ADC_RES=0; //清除ADC結果暫存器RES

    ADC_RESL=0; //清除ADC結果暫存器RESL

    AUXR1 |= 0x04; //調整ADC格式的結果

    }

    void Timer1_rountine(void) interrupt 1

    {}

    unsigned int analogRead(unsigned char channel)

    {

    unsigned int result;

    while (!(ADC_CONTR & ADC_FLAG));//Wait complete flag

    ADC_CONTR &=!ADC_FLAG; //clear ADC FLAG

    result=ADC_RES;

    result=result<<8;

    result+=ADC_RESL;

    // ADC_CONTR|=channel|ADC_POWER|ADC_SPEEDLL|ADC_START;

    return result;

    }

    // Timer 0中斷子程式,每2MS中斷一次,讀取AD值,計算心率值

    void Timer0_rountine(void) interrupt 1

    {

    int N;

    unsigned char i;

    // keep a running total of the last 10 IBI values

    unsigned int runningTotal = 0; // clear the runningTotal variable

    EA=0; // 關定時器中斷

    TL0=T0MS;

    TH0=T0MS>>8; //重灌16位定時器初值

    Pressure = (GetADCResult(PressurePin)); //****************

    DisBuff2[3] = Pressure%10+48;//取個位數

    DisBuff2[2] = Pressure%100/10+48; //取十位數

    DisBuff2[1] = Pressure%1000/100+48; //百位數 ***************

    DisBuff2[0] = Pressure/1000+48;//取千位數

    Signal = GetADCResult(PulsePin); // 讀脈搏感測器

    sampleCounter += 2; // 使用這個值跟蹤記錄脈搏時間間隔在ms級

    N = sampleCounter - lastBeatTime; // 減上個節拍的時間來避免噪聲

    // 找到脈搏波的波峰和波谷

    if(Signal < thresh && N > (IBI/5)*3){ // 如果脈搏感測器輸出小於電源電壓一半 並且 消除噪聲時間小於 3/5個脈搏時間間隔

    if (Signal < Trough){ // 如果脈搏感測器輸出小於波谷

    Trough = Signal; // 跟蹤脈搏波的最低點

    }

    }

    if(Signal > thresh && Signal > Peak){ // 如果輸出大於電源電壓一半並且大於波峰

    Peak = Signal; // 將新值設為波峰

    } // 跟蹤脈搏波的波峰

    if (N > 250){ // 避免高頻噪聲

    if ( (Signal > thresh) && (Pulse == false) && (N > (IBI/5)*3) ){

    Pulse = true; // 當檢測到一個脈搏時將脈搏標誌設為真

    blinkPin=0; // 點亮脈搏燈

    IBI = sampleCounter - lastBeatTime; // 測量兩個脈搏的時間in mS

    lastBeatTime = sampleCounter; // 跟蹤脈搏時間

    if(secondBeat){ // 如果這是第二個脈搏

    secondBeat = false; // 清除標識

    for(i=0; i<=9; i++){ // 全部的資料作為真實脈搏BMP

    rate[i] = IBI;

    }

    }

    if(firstBeat){ // 如果是第一個脈搏

    firstBeat = false; // 清除標誌

    secondBeat = true; // 設定第二脈搏標誌

    EA=1; //開中斷

    return; // IBI 值是不可靠的所以拋棄

    }

    for(i=0; i<=8; i++){ // 移動資料在rate陣列中

    rate[i] = rate[i+1]; // 頂替舊值

    runningTotal += rate[i]; // 加上第九個新值

    }

    rate[9] = IBI; // 加最後的IBI到rate陣列中

    runningTotal += rate[9]; // 加上一個IBI到runningTotal

    runningTotal /= 10; // 取平均值

    BPM = 60000/runningTotal; // 一分鐘可以檢測到多少個心跳及 BPM!

    if(BPM>200)BPM=200; //限制BPM最高顯示值

    if(BPM<30)BPM=30; //限制BPM最低顯示值

    DisBuff[2] = BPM%10+48;//取個位數

    DisBuff[1] = BPM%100/10+48; //取十位數

    DisBuff[0] = BPM/100+48; //百位數

    if(DisBuff[0]==48)

    DisBuff[0]=32;

    QS = true; // 設定QS標誌

    // QS FLAG IS NOT CLEARED INSIDE THIS ISR

    }

    }

    if (Signal < thresh && Pulse == true){ // 當電壓歸零節拍結束

    blinkPin=1; // 熄滅脈搏燈

    Pulse = false; // 重置脈搏標識我們可以重新測

    amp = Peak - Trough; // 得到脈搏波的峰峰值

    thresh = amp/2 + Trough; // 設定thresh位脈搏峰峰值的一半

    Peak = thresh; // 為下一次測試重置波峰

    Trough = thresh;

    }

    if (N > 2500){ //如果超過2.5秒沒有檢測到一個脈搏

    thresh = 512; // 重新設定波谷

    Peak = 512; // 重新設定波峰

    Trough = 512; // 重新設定間隔

    lastBeatTime = sampleCounter; // 把最後的節拍時間更新

    firstBeat = true; // 重新設定標誌避免噪聲

    secondBeat = false; // 當我們得到心跳的時候

    }

    EA=1; // 開中斷

    }// end isr;

    //

    if(Pressure<100){

    for(i=0;i {

    putchar(DisBuff2[i]);依次執行寫入操作

    {

    putchar(ucStr4[i]);

    }

    for(i=0;i<這個是主程式和部分程式碼由於字數限制所以你還是留個郵箱吧

    void main(void)

    {

    unsigned char i

  • 中秋節和大豐收的關聯?
  • 林下養雞要不要圍圍欄?