脉搏测试(程序)_第1页
脉搏测试(程序)_第2页
脉搏测试(程序)_第3页
脉搏测试(程序)_第4页
脉搏测试(程序)_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、#include "msp430g2553.h"#include "lcd12864.h"#define CPU_F (double)1000000)#define delay_us(x) _delay_cycles(long)(CPU_F*(double)x/1000000.0) / 调用delay_us(x); 延时 X us#define delay_ms(x) _delay_cycles(long)(CPU_F*(double)x/1000.0) / 调用delay_ms(2000);延时2000MSextern unsigned char Ke

2、y_Flag;const unsigned char zuobiao;unsigned int ms_count;unsigned char dat,pulse_count=0,Pulse_Input;unsigned int ADC_max=0,ADC_result106=0;unsigned char i,Cap_counter=0;unsigned int Cap_first,Cap_last,cap_time;unsigned char cap_flag,disp7=' ',' ',' ',' ',' ',

3、' ',' ' /存放AD转换的电压值的字符数组disp6,定义格式为123.45Vunsigned char shuzu3=' ',' ',' ' /存放由整形数据转换的字符串unsigned char Pulse_Max3='0','0','0',Pulse_Min3='0','0','0'unsigned char geshu,y_location,x_location;float volt,freq;unsign

4、ed char num_flag=0,Pulse_mHigh,Pulse_mLow; /键盘输入数字计数/* 系统时钟初始化*/void OSCILLATOR_Init(void) if (CALBC1_1MHZ = 0xFF | CALDCO_1MHZ = 0xFF) while(1);/ If calibration constants erased, trap CPU! BCSCTL1 = CALBC1_1MHZ; / Set range DCOCTL = CALDCO_1MHZ;/ Set DCOCLK=1MHz / BCSCTL3 |= LFXT1S_2;/ Set LFXT1 IF

5、G1 &= OFIFG; / Clear OSCFault flag BCSCTL2 |=SELM_1 + DIVM_0; / Set MCLK=DCOCLK=1MHzvoid ADC_Init(void) ADC10CTL0 |= ADC10SHT_2 + ADC10ON ;/ADC10SHTx=10 采样保持时间设为16个ADC10CLK周期,ADC10开启 ADC10CTL0 |= SREF_1 + REFON + REF2_5V; /选择内部参考源2.5V,打开基准源 ADC10CTL1 |= CONSEQ_0 + INCH_1+ SHS_2; / INCHx=0001选择输入

6、通道 A1, / CONSEQ_0, 工作模式为单通道单次采样 ADC10AE0 |= 0x02; / 外部输入通道 A1(P1.1) 使能 /_bis_SR_register(GIE);void Draw_columnPointer(unsigned char x,unsigned char y) lcd_cs0; dat |= 0x01<<(y&0x07); /更新要画点所在的页的字节数据 lcd_address(y/8+1),x); transfer_data_lcd(dat); lcd_cs1;void Draw_rowPointer(unsigned char x

7、,unsigned char y) unsigned char dat=0; /画横向点的时候dat要清零 lcd_cs0; dat |= 0x01<<(y&0x07); /更新要画点所在的页的字节数据 /调用格式 lcd_address(uchar page,uchar column) /page: 18 column:1128 lcd_address(y/8+1),x); transfer_data_lcd(dat); lcd_cs1;void number_to_char(float voltage)/分解成3位整数、2位小数的电压值显示 unsigned char

8、j; /disp0 = (unsigned int)(voltage)/100; /从整数中分离出百位 /voltage -= disp0*100; disp0 = (unsigned int)(voltage)/10; /分离出十位 voltage -= disp0*10; disp1 = (unsigned int)voltage; /分离出个位 voltage -= disp1; disp3 = (unsigned int)(voltage*10); /分离十分位 voltage -= disp3*0.1; disp4 = (unsigned int)(voltage*100);/分离百

9、分位 disp0 |= 0x30; disp1 |= 0x30; disp2 = '.' disp3 |= 0x30; disp4 |= 0x30; /将分离的各位整数转换成字符型数据 disp5 = 'V' disp6 = ' ' for(j=0;j<2;j+) if(dispj = '0') /如果数组中存放在有效整数之前有无效的0,则将'0'用''空格替换 dispj=' ' else break; void inter_to_char(float num) unsign

10、ed char i; shuzu0 = (unsigned int)(num)/100; /从整数中分离出百位 num -= shuzu0*100; shuzu1 = (unsigned int)(num)/10; /分离出十位 num -= shuzu1*10; shuzu2 = (unsigned int)num; /分离出个位 shuzu0 |= 0x30; shuzu1 |= 0x30; shuzu2 |= 0x30; for(i=0;i<2;i+) if(shuzui=0x30) shuzui=0x20; else break; void char_to_number(unsi

11、gned char *dp) unsigned char k; for(k=0;k<3;k+)dpk=dpk-0x30; if(num_flag=1)Pulse_Input = dp0; else if(num_flag=2)Pulse_Input = dp0*10 + dp1; elsePulse_Input = dp0*100 + dp1*10 + dp2;unsigned char i,j,y;/*/void main(void) unsigned char finish_flag=0; WDTCTL = WDTPW + WDTHOLD;/ Stop watchdog timer

12、OSCILLATOR_Init(); /时钟初始化 LCD_IO_Init(); /IO初始程序 Init_lcd(); clear_screen(); /clear all dots P1DIR |= BIT0+BIT2; /P1.0(测试)、P1.2输出(报警指示) P1OUT |= 0x01;/*A/D转换设置*/ ADC10CTL1 |= INCH_1+ SHS_1; /INCHx=0001选择输入通道 A1(P1.1管脚);采样保持源TA1 ADC10AE0 = 0x02; / 外部输入通道 A1 使能/*定时比较触发AD转换*/ TACCTL0 = CCIE; TACCR0 = 4

13、0-1; / 采样周期40us TACCTL1 = OUTMOD_3; /比较模式3, TACCR1 toggle TACCR1 = 2; TACTL = TASSEL_2 + MC_1; / SMCLK, Upmode/*捕获功能设置* 定时器Timer1的TA1CCR2捕获信号选择为TA1.2,由P2.4输入,CCI2A输入*/ P2DIR &= BIT4; P2SEL |= BIT4; /TA1.2/P2.4 Timer1_A CCI2A TA1CCTL2 |= CM_1 + SCS + CAP + CCIS_0 + CCIE;/上升沿、同步捕获,CCI2A TA1CTL |=

14、TASSEL_1 + ID_3 + MC_2+ TACLR ;/ACLK=32768HZ,8分频为4096;连续计数模式/*/ display_GB2312_string(1,1,"人体脉搏测试系统"); display_GB2312_string(3,8,"A-输入脉搏上限"); display_GB2312_string(5,8,"B-输入脉搏下限"); display_GB2312_string(7,8,"C-脉搏图形显示"); delay_ms(3000); while(1) /i=0; Key_Scan(

15、); /做键扫描 if(Key_Flag) /如果Key_Flag标志不为0,则有键按下 Key_Flag = 0; delay_ms(15); Key_Value(); /做按键键值的判断 if(Key_Flag = 'A') /等待输入脉搏上限值 clear_screen();display_GB2312_string(1,1,"最大脉搏次数:");display_string_57(8,71,"F->EXIT");delay_ms(1000);while(1) Key_Scan(); /做键扫描 if(Key_Flag) /如

16、果Key_Flag标志不为0,则有键按下 Key_Flag = 0; delay_ms(15); Key_Value(); switch(Key_Flag) case '1':Pulse_Maxnum_flag='1'break; case '2':Pulse_Maxnum_flag='2'break; case '3':Pulse_Maxnum_flag='3'break; case '4':Pulse_Maxnum_flag='4'break; case '

17、;5':Pulse_Maxnum_flag='5'break; case '6':Pulse_Maxnum_flag='6'break; case '7':Pulse_Maxnum_flag='7'break; case '8':Pulse_Maxnum_flag='8'break; case '9':Pulse_Maxnum_flag='9'break; case '0':Pulse_Maxnum_flag='0

18、9;break; case 'F':finish_flag=1;break; default: break; if(num_flag=3) num_flag=0; if(!finish_flag) /数据输入并显示 display_5x7(5,20+num_flag*7,Pulse_Maxnum_flag);num_flag+; else finish_flag=0; char_to_number(Pulse_Max);/输入字符转换成数字 Pulse_mHigh=Pulse_Input; num_flag=0; /输入数据结束,退出数据输入和显示循环 clear_screen

19、(); display_GB2312_string(3,8,"A-输入脉搏上限"); display_GB2312_string(5,8,"B-输入脉搏下限"); display_GB2312_string(7,8,"C-脉搏图形显示"); break; if(Key_Flag = 'B') /等待输入脉搏上限值 clear_screen(); display_GB2312_string(1,1,"最小脉搏次数:"); display_string_57(8,71,"F->EXIT&

20、quot;); delay_ms(1000); while(1) Key_Scan(); /做键扫描 if(Key_Flag) /如果Key_Flag标志不为0,则有键按下 Key_Flag = 0; delay_ms(15); Key_Value(); switch(Key_Flag) case '1':Pulse_Minnum_flag='1'break; case '2':Pulse_Minnum_flag='2'break; case '3':Pulse_Minnum_flag='3'bre

21、ak; case '4':Pulse_Minnum_flag='4'break; case '5':Pulse_Minnum_flag='5'break; case '6':Pulse_Minnum_flag='6'break; case '7':Pulse_Minnum_flag='7'break; case '8':Pulse_Minnum_flag='8'break; case '9':Pulse_Minnum_f

22、lag='9'break; case '0':Pulse_Minnum_flag='0'break; case 'F':finish_flag=1;break; default: break; if(num_flag=3) num_flag=0; if(!finish_flag) /数据输入并显示 display_5x7(5,20+num_flag*7,Pulse_Minnum_flag);num_flag+; else finish_flag=0; char_to_number(Pulse_Min);/输入字符转换成数字 Pul

23、se_mLow=Pulse_Input; num_flag=0; /输入数据结束,退出数据输入和显示循环 clear_screen(); display_GB2312_string(3,8,"A-输入脉搏上限"); display_GB2312_string(5,8,"B-输入脉搏下限"); display_GB2312_string(7,8,"C-脉搏图形显示"); break; if(Key_Flag = 'C') clear_screen();display_12864(zuobiao);display_stri

24、ng_57(8,7,"Vm");display_string_57(8,38," ");display_string_57(8,76,"Pu");display_string_57(8,110,"/s");_EINT(); /开总中断 #pragma vector=TIMER0_A0_VECTOR /定时器Timer0中断_interrupt void Timer_A0_ISR(void)ADC10CTL0 |= ADC10SHT_2 + ADC10ON + ADC10IE;/ADC10SHTx=10 采样保持时间

25、设为16个ADC10CLK周期,ADC10开启ADC10CTL0 |= SREF_1 + REFON + REF2_5V; /选择内部参考源2.5V,打开基准源/ADC10CTL0 |= SREF_1 + REFON; /选择内部参考源1.5V ADC10CTL0 |= ENC; / ADC10 enable set/将脉搏的电信号进行AD转换,并画出脉搏波形#pragma vector=ADC10_VECTOR_interrupt void ADC10_ISR(void)ADC10CTL0 &= ENC; / ADC10 disabledADC10CTL0 = 0; / ADC10,

26、 Vref disabled completelyif(pulse_count < 106) ADC_resultpulse_count = ADC10MEM; /每次采样结果送入数组 geshu = ADC_resultpulse_count*35/1023; y_location = 64-(18+geshu); x_location = 15+pulse_count; Draw_rowPointer(x_location,y_location); /扫描点送显 if(ADC_max < ADC_resultpulse_count) /取波形每帧图像中的电压最大值 ADC_ma

27、x = ADC_resultpulse_count;else pulse_count=0; ADC_max = 0; i = 0; clear_area(); /显示区域刷新;pulse_count+;volt = (ADC_max*2.5)/1023;number_to_char(volt);display_string_57(8,21,disp); /显示每一帧数据中的峰值#pragma vector=TIMER1_A1_VECTOR /Timer1_A通道2捕获脉搏周期时间_interrupt void Timer1_A2_ISR(void)switch(_even_in_range(T

28、A1IV,0x0A) case TA1IV_NONE: break; / Vector 0: No interrupt case TA1IV_TACCR1:break; / Vector 2: TACCR1 CCIFG case TA1IV_TACCR2: / Vector 4: TACCR2 CCIFG if (TA1CCTL2 & CCI) / Capture Input Pin Status P1OUT = 0x01; / Rising Edge was captured if (Cap_counter=0) Cap_first= TA1CCR2; /第一次捕获上升沿的计数值 C

29、ap_counter+; cap_flag=0; else Cap_last = TA1CCR2; /第二次捕获上升沿的计数值 Cap_counter=0; cap_flag=1; _DINT(); /关中断,禁止响应任何中断,避免破坏捕获数据 if(cap_flag=1) /完成2次捕获,即可计算周期 cap_time = Cap_last - Cap_first; if(cap_time) freq=(float)4096/cap_time); freq *= 60; /计算频率,x次/分钟 if(unsigned int)(freq)>Pulse_mHigh | (unsigned

30、 int)(freq)<Pulse_mLow) P1OUT |= BIT2; else P1OUT &= BIT2; inter_to_char(freq); display_string_57(8,91,shuzu); /显示每分钟的脉搏次数 /else /freq=0; _EINT(); /开总中断 break; case TA1IV_6: break; / Vector 6: Reserved CCIFG case TA1IV_8: break; / Vector 8: Reserved CCIFG case TA1IV_TAIFG: break; / Vector 10:

31、 TAIFG default: break; const unsigned char zuobiao= 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x8

32、0,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x8

33、0,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0E,0x18,0x0E,0x03,0x00,0xFF,0x84,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0

34、0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0

35、0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0

36、0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0

37、0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0

38、0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0

39、0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x08,0x00,0x00,0x00,0x0

40、0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0

41、0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0

42、0,0x00,0x00,0xFF,0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论