程序如下:- #define DAC_1 XBYTE[0x2000]
- #define DAC_2 XBYTE[0x4000]
- #define ADC_0 XBYTE[0x6000]
- #define ADC_1 XBYTE[0x6001]
- #define ADC_2 XBYTE[0x6002]
- #define ADC_3 XBYTE[0x6003]
- #define ADC_4 XBYTE[0x6004]
- #define ADC_5 XBYTE[0x6005]
- #define ADC_6 XBYTE[0x6006]
- #define ADC_7 XBYTE[0x6007]
- unsigned char dspbuf[4]={0xef,0xef,0xef,0xef},sel=0,key_sta=0,key_num;
- unsigned int adcount=0;
- sbit D_SER =P1^0;
- sbit D_SRCLK =P1^1;
- sbit D_RCLK =P1^2;
- sbit KEY1 =P3^4;
- sbit KEY2 =P3^5;
- 定时器初始化:
- void init_timer0(void)
- {
- TMOD TMOD =0X22; //定时器0以方式2(自动重新装载8位计数器)自动计数
- TL0 = 0X06;
- TH0 = 0X06; //至初始值为6,每0.25ms进入一次中断
- TL1 = 0Xe8;
- TH1 = 0Xe8;
- TR0 = 1;
- TR1 = 1;
- ET0 = 1;
- }
- 中断设置:
- void init_special_interrupts(void)
- {
- EX0 = 0;
- ET0 = 1;
- EX1 = 0;
- ET1 = 0;
- ES = 1;
- EA = 1;
- PT0 = 0;
- PX1 = 1;
- PS = 0;
- SCON=0x50; //串行口方式1工作
- }
- 数码管显示:
- void dsptask()
- {
- unsigned chari;
- unsigned chara,b;
- switch(sel)
- {
- case 0:a=0x01; break;
- case 1:a=0x02; break;
- case 2:a=0x04; break;
- default:a=0x08;
- }
- for(b=0x80,i=0;i<8;i++)
- {
- if(a&b) D_SER=1;
- else D_SER=0;
- D_SRCLK=0;
- D_SRCLK=1;
- D_SRCLK=0;
- b=b>>1; b=b&0x7f;
- }
- a=dspbuf[sel];
- key_num=sel;
- sel++;
- if(sel>=4)sel=0;
- for(b=0x80,i=0;i<8;i++)
- {
- if(a&b) D_SER=1;
- else D_SER=0;
- D_SRCLK=0;
- D_SRCLK=1;
- D_SRCLK=0;
- b=b>>1; b=b&0x7fff;
- }
- D_RCLK=0;
- D_RCLK=1;
- D_RCLK=0;
- }
- 键盘扫描: //键盘值为1~8
- void key_service()
- {
- if(key_sta&0x01) return; // key_sta.0=1
- if(KEY2)
- {
- key_num=key_num+1;
- key_sta=key_sta|0x01; // 置key_sta.0=1
- }
- else if(KEY1)
- {
- key_num=key_num+5;
- key_sta=key_sta|0x01; // 置key_sta.0=1
- }
- }
- 定时器0中断处理:
- void timer_isr() interrupt 1 {
- EA=0;
- adcount++; //计数,便于放气速度设置
- key_service(); //键盘扫描
- EA=1;
- }
- 扫描字显示转化:
- fdisp(unsigned char n,unsigned char m) //将需要显示的数转化成相应的显示码
- {
- char c;
- switch(n)
- {
- case 0: c=0x11; break;
- case 1: c=0x7d; break;
- case 2: c=0x23; break;
- case 3: c=0x29; break;
- case 4: c=0x4d; break;
- case 5: c=0x89; break;
- case 6: c=0x81; break;
- case 7: c=0x3d; break;
- case 8: c=0x01; break;
- default:c=0x09;
- }
- dspbuf[m]=c;
- }
- 主函数:
- void main(void)
- {
- floatmax=0,min=0,minus=0,mmax=0,om=0;
- intos=0,od=0,os0=0,os1=0,os2=0,od0=0,od1=0,od2=0;
- unsignedchar t,i,flag=0,high=0,hhigh=0,ave=0;
- init_timer0(); //初始化定时器0
- init_special_interrupts(); //设置中断
- for(i=0;i<4;i++){fdisp(0,i);}
- dsptask();
- for(;;)
- {
- if(key_num==1) //开始放气
- {
- key_sta=key_sta&0xfe; // 置key_sta.0=0
- t=ADC_0;
- if(t>max)max=t;
- elseif(t<min) min=t;
- if(adcount>199)
- {
- adcount=0;
- DAC_1=0xf0; //由D/A输出来控制放气速度
- if(min!=0&&max!=0) {minus=max-min;if(minus>mmax){mmax=minus;ave=min;}}
- }
- } //求出振荡波峰峰值最大时平均压对应的电压值
- elseif(key_num==2) //停止放气,求出所需数值并显示
- {
- key_sta=key_sta&0xfe;
- if(adcount>199)adcount=0;
- max=0;
- min=0;
- minus=0;
- om=ave/(28*3.5*0.133);
- //常数28为放大倍数,根据硬件的实际情况可有所调整
- os=om*0.8;
- od=om*0.5; //根据固定比率法求出收缩压和舒张压,单位为mmHg
- if(os>140||od>90)high=1;
- if(os>160||od>100){high=0;hhigh=1;}
- //收缩压大于160mmHg为超高血压,大于130mmHg为高血压
- os2=os/100;
- os=os%100;
- os1=os/10;
- os0=os%10;
- od2=od/100;
- od=od%100;
- od1=od/10;
- od0=os%10;
- do{
- if(flag=0&&adcount>199) //显示收缩压
- {
- adcount=0;
- flag=1;
- fdisp(os0,0);
- fdisp(os1,1);
- fdisp(os2,2);
- fdisp(0,3);
- dsptask();
- }
- elseif(flag=1&&adcount>199)
- {
- adcount=0;
- flag=0;
- fdisp(od0,0);
- fdisp(od1,1);
- fdisp(od2,2);
- fdisp(0,3);
- dsptask(); //显示舒张压
- if(adcount>199!=key_num!=3)
- {
- if(high==1)
- {
- fdisp(1,0);
- fdisp(0,1);
- fdisp(0,2);
- fdisp(0,3);
- dsptask();
- } //显示高血压
- elseif(hhigh==1)
- {
- fdisp(2,0);
- fdisp(0,1);
- fdisp(0,2);
- fdisp(0,3);
- dsptask();
- } //显示超高血压
- else
- {
- for(i=0;i<4;i++)fdisp(0,i);
- dsptask();
- } //显示血压正常
- }
- }
- }while(key_num!=3);
- }
- elseif(key_num==3) //复位
- {
- key_sta=key_sta&0xfe; // 置key_sta.0=0
- for(i=0;i<4;i++){fdisp(0,i);}
- dsptask();
- high=0;
- hhigh=0;
- max=0,min=0,minus=0,mmax=0,om=0;
- os=0,od=0,os0=os1=os2=0,od0=od1=od2=0;
- flag=0;
- if(adcount>199)adcount=0;
- }
- elsekey_sta=key_sta&0xfe; // 置key_sta.0=0;
- }
- }
复制代码但试了一下,无法实现,求助
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>