void SPO2H(int transmit_mode) { USE_LCD(); SpO2_lcd(); int_adc(); Init_UART2(); UCA0IE |= UCRXIE; //PMM_setVCore(PMM_BASE, PMM_CORE_LEVEL_2); initClocks(20000000); // Config clocks. MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz delay_2(); delay_2(); // USB_setup(TRUE,TRUE); BUTTON_S4=0; while(!(buttonsPressed & BUTTON_S4)) { Init_UART2(); UCA0IE |= UCRXIE; _EINT(); // delay_2(); // delay_2(); ad(); if(BUTTON_S4==0){ on_ired(); wave(1); //显示红光 /* for(i=0;i<480;i++){ results[i+480]=results[i]; }*/ NONUSE_LCD(); save(); // 前0-480为红外 1000-1480为 // delay_2(); // delay_2(); ad(); if(BUTTON_S4==0){ on_red(); wave(0); //显示红外 unsigned int count=0; //ired unsigned int count1=0; //red unsigned int count_spa=0; unsigned int count1_spa=0; //调试时 使用 int red_hr=0; int hr = 0; //心率 unsigned int j = 0, j1 = 0; for(i = 9; i < max-10 ;i++) //ired { if(results[i]>=results[i+1]&&results[i]>=results[i+2]&&results[i]>=results[i+3]&&results[i]>=results[i-1]&&results[i]>=results[i-2]&&results[i]>=results[i-3]&&j<4&& results[i]>=results[i+4]&&results[i]>=results[i+5]&&results[i]>=results[i+6]&&results[i]>=results[i-4]&&results[i]>=results[i-5]&&results[i]>=results[i-6]&& results[i]>=results[i+7]&&results[i]>=results[i+8]&&results[i]>=results[i+9]&&results[i]>=results[i-7]&&results[i]>=results[i-8]&&results[i]>=results[i-9]) { r_locate[count] = i; count++; if(count>=10)break; i = i+40; } } for(i = 9+480; i < max-10+480 ;i++) //red { if(results[i]>=results[i+1]&&results[i]>=results[i+2]&&results[i]>=results[i+3]&&results[i]>=results[i-1]&&results[i]>=results[i-2]&&results[i]>=results[i-3]&&j1<4&& results[i]>=results[i+4]&&results[i]>=results[i+5]&&results[i]>=results[i+6]&&results[i]>=results[i-4]&&results[i]>=results[i-5]&&results[i]>=results[i-6]&& results[i]>=results[i+7]&&results[i]>=results[i+8]&&results[i]>=results[i+9]&&results[i]>=results[i-7]&&results[i]>=results[i-8]&&results[i]>=results[i-9]) { r1_locate[count1] = i; count1++; if(count1>=10)break; i=i+40; } } /*计算心率 其实最后一个峰值坐标减去第一个 再除以个数就可以了哦*/ count_spa = count - 1; count1_spa = count1 - 1; hr = (r_locate[count_spa]-r_locate[0])/count_spa; hr=(1.0/(float)(hr*0.01))*60; red_hr = (r1_locate[count1_spa]-r1_locate[0])/count1_spa; red_hr=(1.0/(float)(red_hr*0.01))*60; // /*直流算平均值*/ red_dc = 0.0; ired_dc = 0.0; length_idc = (float)(r_locate[count_spa]-r_locate[count_spa -2]); //ired length_dc = (float)(r1_locate[count1_spa] - r1_locate[count1_spa -2]); for(i = r1_locate[count1_spa -2] ; i <r1_locate[count1_spa];i++) //最后的位置是采样到最后一个峰峰值的坐标 { red_dc += (float)results1[i]/length_dc; } for(i = r_locate[count_spa -2] ; i <r_locate[count_spa];i++) //最后的位置是采样到最后一个峰峰值的坐标 { ired_dc += (float)results1[i]/length_idc; } /*最小值及交流峰峰值 最后2个周期才稳定 可以用最后2个周期算峰峰值*/ /*同时 红光用前一个峰值减去谷值 红外用后一个峰值减去谷值 去基线漂移*/ red_min = results[1+480];//(float)red[0]; ired_min = results[1];//(float)results[0]; 避免第一个数采得不准 ired_ac = 0; red_ac = 0; for(i =( count_spa -2); i <count_spa ;i++) //ired { for(j=r_locate[i]; j < r_locate[i+1] ;j++) { if(results[j]<ired_min){ired_min=results[j];} } ired_ac += results[r_locate[i+1]] - ired_min; nr_locate[i]=ired_min; ired_min = results[1]; //更新初值 } ired_ac = ired_ac/2; for(i = (count1_spa -2); i <count1_spa ;i++) //red { for(j=r1_locate[i]; j < r1_locate[i+1] ;j++) { if(results[j]<red_min){red_min=results[j];} } red_ac += results[r1_locate[i]] - red_min; nr1_locate[i] = red_min; red_min = results[481]; } red_ac = red_ac/2; /*计算血氧含量*/ Q1 = (float)(red_ac/red_dc); Q2 = (float)ired_ac/(float)ired_dc ; Q = Q1/Q2 ; sao2 = (-4.1768)*Q + 100.9352 + 0.5; if(abs(hr-red_hr)>=10) //两次采样的心率值相差不大的情况下才更新Q { Q = pre_Q; } /*显示*/ USE_LCD(); SPILCD_Clear_Lim(212,260,18,52,WHITE); //371 355 SPILCD_Clear_Lim(348,396,18,52,WHITE); unsigned int temp1,temp10,temp100; long temp_final1; long temp_final2; temp1=hr%10; //计算心率个位 temp10=(hr%100-temp1)/10; //计算心率十位 temp100=(hr-temp10*10-temp1)/100; //计算心率百位 temp_final1=(long)(temp1+temp10*10+temp100*100); if(temp100>0) DRAW_NUM(244,20,temp100,BLUE); //显示心率百位 DRAW_NUM(228,18,temp10,BLUE); //显示心率十位 DRAW_NUM(212,18,temp1,BLUE); //显示心率个位 sao2=99; temp1=sao2%10; //计算个位 temp10=(sao2%100-temp1)/10; //计算十位 temp100=(sao2-temp10*10-temp1)/100; //计算百位 temp_final2=(long)(temp1+temp10*10+temp100*100); if(temp100>0) DRAW_NUM(380,18,temp100,BLUE); //显示心率百位 DRAW_NUM(364,18,temp10,BLUE); //显示十位 DRAW_NUM(348,18,temp1,BLUE); //显示个位 NONUSE_LCD(); i = 0; pre_Q = Q; //记录这次显示的Q /* char start[7]={'S','T','A','R','T','S','O'}; long a; char b[5]; char c[3]; char d[3]; ltoa(temp_final1,b); if(temp_final1>=0&&temp_final1<=9) { c[0]='0'; c[1]='0'; c[2]=b[0]; } if(temp_final1>=10&&temp_final1<=99) { c[0]='0'; c[1]=b[0]; c[2]=b[1]; } if(temp_final1>=100&&temp_final1<=999) { c[0]=b[0]; c[1]=b[1]; c[2]=b[2]; } ltoa(temp_final2,b); if(temp_final2>=0&&temp_final2<=9) { d[0]='0'; d[1]='0'; d[2]=b[0]; } if(temp_final2>=10&&temp_final2<=99) { d[0]='0'; d[1]=b[0]; d[2]=b[1]; } if(temp_final2>=100&&temp_final2<=999) { d[0]=b[0]; d[1]=b[1]; d[2]=b[2]; } char end[3]={'E','N','D'}; j=0; for(j=0;j<960;j++) //采样数据除以40转化成两位,便于传送 { results[j]=results[j]/40; }*/ int i; for(i=959;i>=0;i--) { results[i+10]=results[i]>>5; } results[0]='S'; results[1]='T'; results[2]='A'; results[3]='R'; results[4]='T'; results[5]='S'; results[6]='O'; if(hr>=127){ results[7]=0x7F; results[8]=(char)(hr-127);} else{ results[7]=(char)(hr); results[8]=0; } results[9]=sao2; results[970]='A'; results[971]='A'; results[972]='A'; results[973]='A'; results[974]='A'; // results[974]=0x7F; results[975]='E'; results[976]='N'; results[977]='D'; // CRCresult=0; // for(i=9;i<969;i++) // { // results[i]=results[i]>>5; // CRCtmp = CRCresult%256; // CRCindex = CRCtmp^results[i]; // CRCtmp = CRCresult/256; //除以256 // CRCresult = CRCtmp; // CRCresult = CRCresult^CRC_TA[CRCindex]; // } // long a; // char b[5]; // a=CRCresult; // ltoa(a,b); // results[969]=b[0]; // results[970]=b[1]; // results[971]=b[2]; // results[972]=b[3]; // results[973]=b[4]; // results[974]='E'; // results[975]='N'; // results[976]='D'; if(transmit_mode==1){ bcUartInit(); bcUartSend_char(results,978);//buf_bcuartToUsb } if(transmit_mode==2){ hidSendDataInBackground(results,1956, HID0_INTFNUM,10000); } if(transmit_mode==3){ int i; for(i=0;i<978;i++) { UCA0TXBUF = results[i]; while(!(UCTXIFG==(UCTXIFG & UCA0IFG))&&((UCA0STAT & UCBUSY)==UCBUSY)); int a,k; for(a=0;a<10;a++) { for(k=0;k<80;k++); } } } BUTTON_S4=0; buttonsPressed=0; NONUSE_LCD(); } }
void ProcessInt0() { uint8 nAsrResCount=0; EX0=0; ucRegVal = LD_ReadReg(0x2B); if(nLD_Mode == LD_MODE_ASR_RUN) { // 语音识别产生的中断 // (有声音输入,不论识别成功或失败都有中断) LD_WriteReg(0x29,0) ; LD_WriteReg(0x02,0) ; if((ucRegVal & 0x10) && LD_ReadReg(0xb2)==0x21 && LD_ReadReg(0xbf)==0x35) { nAsrResCount = LD_ReadReg(0xba); if(nAsrResCount>0 && nAsrResCount<=4) { nAsrStatus=LD_ASR_FOUNDOK; } else { nAsrStatus=LD_ASR_FOUNDZERO; } } else { nAsrStatus=LD_ASR_FOUNDZERO; } LD_WriteReg(0x2b, 0); LD_WriteReg(0x1C,0); return; } // 声音播放产生的中断,有三种: // A. 声音数据已全部播放完。 // B. 声音数据已发送完毕。 // C. 声音数据暂时将要用完,需要放入新的数据。 ucHighInt = LD_ReadReg(0x29); ucLowInt=LD_ReadReg(0x02); LD_WriteReg(0x29,0) ; LD_WriteReg(0x02,0) ; if(LD_ReadReg(0xBA)&CAUSE_MP3_SONG_END) { // A. 声音数据已全部播放完。 LD_WriteReg(0x2B, 0); LD_WriteReg(0xBA, 0); LD_WriteReg(0xBC,0x0); bMp3Play=0; // 声音数据全部播放完后,修改bMp3Play的变量 LD_WriteReg(0x08,1); delay_2(5); LD_WriteReg(0x08,0); LD_WriteReg(0x33, 0); return ; } if(nMp3Pos>=nMp3Size) { // B. 声音数据已发送完毕。 LD_WriteReg(0xBC, 0x01); LD_WriteReg(0x29, 0x10); // bMp3Play=0; // 此时,只是主控MCU把所有MP3数据发送到LD3320芯片内,但是还没有把送入的数据全部播放完毕 EX0=1; return; } // C. 声音数据暂时将要用完,需要放入新的数据。 LD_ReloadMp3Data_2(); LD_WriteReg(0x29,ucHighInt); LD_WriteReg(0x02,ucLowInt) ; delay_2(10); EX0=1; }