Chinaunix首页 | 论坛 | 博客
  • 博客访问: 208887
  • 博文数量: 56
  • 博客积分: 1085
  • 博客等级: 少尉
  • 技术积分: 652
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-29 13:50
文章分类
文章存档

2014年(4)

2012年(25)

2011年(27)

我的朋友

分类: Delphi

2011-09-29 15:16:00

//#include
#include
#include
#include
#include "ht1625.h"
#include "eep.h"
#define uchar  unsigned char
#define uint   unsigned int
#define ulong  unsigned long
     
uchar code Number[20]={
   0x0d,0x07, //0
   0x00,0x06, //1
   0x0e,0x03, //2
   0x0a,0x07, //3
   0x03,0x06, //4
   0x0b,0x05, //5
   0x0f,0x05, //6
   0x00,0x07, //7
   0x0f,0x07, //8
   0x0b,0x07  //9
};
sbit S_Enter=P2^0;
sbit S_Add=P2^1;
sbit S_Reduce=P2^2;
sbit S_Rate=P1^6;
sbit S_Program=P1^7;
sbit BZ=P2^4;
sbit Left=P3^1;
sbit Right=P3^2;
sbit Heart=P3^3;
/*******idata************/
uchar idata P_Num=1;
uchar idata M_Num=0;
uchar idata MaxDistance=0;
//uchar idata PNumber0;
//uchar idata PNumber1;
uchar idata PD1=0;
uchar idata PD2=0;
uchar idata PD3=0;
uchar idata PD4=0;
int   idata add=0;
uint  idata XNumber=0;
uint  data  Wzero=0;              
//uint  xdata Wzero0=0;
uint  idata H_Rate=0;
uint  idata HRateTime=0;
uint  idata ZeroHRateTime=0;
uint  idata Time20;
//float idata WorkEnergyZero=0;
ulong idata JGTime=0;//
uchar data i1=0;
uchar data j1=0;
//uchar data cj=0;
uchar data Fvalue=0;
uchar idata Ctemp=0;
float data  set[6]={0};
int   xdata FirstValue[21]={0};
float xdata P_Time[12]={0};
 int  data  W_weight0;
 int  data  W_weight1;
//int   idata Cl[10]={0};
//ulong idata SUM=0;
/*********data***********/
bit   WorkOut0=0;
bit   WorkOut1=0;
bit   Operating=0;
bit   Exercise=0;
bit   Check=0;
bit   SetUp=0;
bit   Standard=0;
bit   ArtBeat=0;
bit   RedUp=0;
bit   WaveDisplaySignal=0;
uchar  idata key=0;
uchar  data count=0;
uchar  data flag=0;
ulong  data x=0;
int    data rk1=0;
int    data rk0=0;
float  data k=0;
float  data b=0;
/********增加内容***************/
uint  idata hk0=0;
uint  idata hk1=0;
//uchar idata htemp;
uchar idata hflag=0;
uchar idata hhflag=0;
/******************************/
int   data  Gear=0;
int   idata Gear0=0;
uint  idata HRateNumber=0;
ulong data  TimeNumber=0;
uint  data  WorkCounter=0;
int   data  WorkWeight=0;
//int   WorkWeightZero=0;
uint  idata WorkOverTime=0;
float data  WorkPower=0;
float data  WorkEnergy=0;
  
uchar data  MaxGear=0;
uchar data  MinGear=0;
//uchar UpMinGear=0;
ulong data  RedStartTime=0;
ulong data  RedStartTimeZero=0;
ulong data  RedUpTime=0;
uchar data  WaveDisplayTime=0;
//ulong UpTimer=0;
//uint  UpDistance=0;
void delay(uint z);
void InitTimer(void);
void KeyBoard(void);
void Install(void);
void Standardization(void);
void CheckState(void);
void HeartRate(void);
void WorkState(void);
void WaveDisplay(void);
void redweiyi(void);
void main()
{
  AUXR=0x01;
  INIT_LCD();
  InitTimer();
  ALLLIGHT(); //LCD AND HT1625初始化
  delay(3000);
  CLEAR();
  //Wzero=x;
  //zero=x;
  while(1)
     {
      Install();
      Standardization();
   CheckState();
   HeartRate();
   WorkState();
   //E
      Writedata(94,0x0f);
      Writedata(96,0x01);
   //设备号
      Writedata(98,Number[2*(M_Num/10)]);
   Writedata(100,Number[2*(M_Num/10)+1]);
      Writedata(102,Number[2*(M_Num%10)]);
   Writedata(104,Number[2*(M_Num%10)+1]);
   //P
      Writedata(82,0x07);
   Writedata(84,0x03);
   //0 
      Writedata(86,0x0d);
   Writedata(88,0x07);
   //程序号
   Writedata(90,Number[2*P_Num]);
   Writedata(92,Number[2*P_Num+1]);        
  };
}
/***********粗延时1ms程序***********/
void delay(uint z)
{
  uint i;
  uint j;
  for(i=z;i>0;i--)
     for(j=123;j>0;j--);
}
/***********程序初始化************/
void InitTimer(void)
{
  uchar i,j;
  union {
        uchar p[4];
        float fbuf;
       }floa_data;
  BZ=0;
  x=0;
  rk0=0;
  rk1=0;
  flag=0;
  key=0;
  Gear=0;
  ArtBeat=0;
  Exercise=0;
  floa_data.fbuf=0;
  M_Num=eeprom_read(0x8000);
  for(i=0;i<6;i++)
     {
    for(j=0;j<4;j++)
       {
             floa_data.p[j]=eeprom_read(0x8001+4*i+j);
          }      
       set[i]=floa_data.fbuf;
  }
  for(i=0;i<12;i++)
     {
    for(j=0;j<4;j++)
       {
             floa_data.p[j]=eeprom_read(0x8020+4*i+j);
          }      
       P_Time[i]=floa_data.fbuf;
  } 
  MaxDistance=eeprom_read(0x8019);
  JGTime=eeprom_read(0x8050);
  for(j=0;j<4;j++)
  {
        floa_data.p[j]=eeprom_read(0x8200+j);
     }      
  k=floa_data.fbuf;
  if(M_Num>32)
    {
    FirstValue[0]=1;
 FirstValue[1]=100;
 FirstValue[2]=100;
 FirstValue[3]=40;
 FirstValue[4]=4;
 FirstValue[5]=4;
 FirstValue[6]=-113;
 FirstValue[7]=50;
    FirstValue[8]=180;
 FirstValue[9]=0;
 FirstValue[10]=180;
 FirstValue[11]=180;
 FirstValue[12]=90;
 FirstValue[13]=180,
 FirstValue[14]=180;
 FirstValue[15]=180;
 FirstValue[16]=180;
 FirstValue[17]=300;
 FirstValue[18]=0;
 FirstValue[19]=100;
 FirstValue[20]=20; 
 }
  else
    {
    FirstValue[0]=M_Num;
    FirstValue[1]=set[0]*10;
     FirstValue[2]=set[1]*100;
     FirstValue[3]=set[2]*1000;
     FirstValue[4]=set[3]*1000;
     FirstValue[5]=set[4]*1000;
       FirstValue[6]=set[5]*1000;
     FirstValue[7]=MaxDistance;
    FirstValue[8]=P_Time[0]*100;
     FirstValue[9]=P_Time[1]*100;
     FirstValue[10]=P_Time[2]*100;
     FirstValue[11]=P_Time[3]*100;
     FirstValue[12]=P_Time[4]*100;
       FirstValue[13]=P_Time[5]*100;
    FirstValue[14]=P_Time[6]*100;
    FirstValue[15]=P_Time[7]*100;
     FirstValue[16]=P_Time[8]*100;
     FirstValue[17]=P_Time[9]*100;
     FirstValue[18]=P_Time[10]*100;
     FirstValue[19]=P_Time[11]*100;
       FirstValue[20]=JGTime*10;
  }
//****************************************//
  TMOD=0x15;      //T0为计数器,
  TH0=0;       //T1为工作方式1的16位定时器
  TH1=0;
  TH1=(65536-50000)/256;
  TL1=(65536-50000)%256;
  T2CON=0x04;      //定时器2的16位自动装载
  RCAP2H=(65536-20000)/256;     
  RCAP2L=(65536-20000)%256;
  IPH=0x2a;
  IP=0x24;
/*
  PT2=1;
  PT2H=1;
  PT1=0;
  PT1H=1;
  PT0=0;
  PT0H=1;
  PX1=1;
  PX1H=0;
  PX0=0;
  PX0H=0;
 */  
  EA=1;  // 中断允许总开关
  ET0=1; // T0中断允许
  ET1=1;    // T1中断允许
  ET2=1;    // T2中断允许
  TR0=1;    // 定时器T2运行
  TR1=1;    // 定时器T1运行
  TR2=1;    // 计数器T0运行
  EX0=1;    // INT0允许
  IT0=1;    // INT0下降沿触发中断 
}
//************按键子程序***************
void KeyBoard(void)
{
  if((P2&0x07)!=0x07)
    {
      TR1=0;    // 定时器T1运行
      TR0=0;    // 计数器T0运行  
   delay(10);
   if((P2&0x07)!=0x07)
  {
    key++;
    if(key==9)
      {
      key=0;
      switch(P2&0x07)
            {
        case 0x01 :
             if (BZ==0)
          {
           Check=~Check;
        BZ=1;
          }                       
          break;             //检测状态,同时按下 + 和 —
        case 0x02 : SetUp=1;break;     //设置状态,同时按下 ENTER 和 —
        case 0x04 : Standard=1;break;  //标定状态,同时按下 ENTER 和 +
           case 0x05 : add++;break;       //加
        case 0x03 : add--;break;       //减
      }  
   }
  }
   TR1=1;    // 定时器T1运行
      TR0=1;    // 计数器T0运行
 }  
  else
    {
   if(!S_Program)
     {
    TR1=0;    // 定时器T1运行
          TR0=0;    // 计数器T0运行
    delay(10);
    if(!S_Program)
      {
     key++;
     if(key==9)
       {
      key=0;
      if(!Operating)
     {
       P_Num++;
       if(P_Num==6) 
          P_Num=1;
     }
      else
     {
       if(WorkOut0)
         {
          WorkOut1=1;
       BZ=0;      
      }
       else
         {
                      TimeNumber=0;
                      WorkWeight=0;
                      W_weight0=0;
                      W_weight1=0;
                      WorkOverTime=0;
                      WorkCounter=0;
                      WorkPower=0;
                      WorkWeight=0;
                      WorkEnergy=0;
//                      WorkEnergyZero=0;
       Gear=0;
                      MaxGear=0;
                      MinGear=0;
//                    UpMinGear=0;
                      RedStartTime=0;
                      RedStartTimeZero=0;
                      RedUpTime=0;
       XNumber=0;
                      WaveDisplayTime=0;
                      WaveDisplaySignal=0; 
       WorkOut0=1;            
      }
         
     }
    }
   }
    TR1=1;    // 定时器T1运行
          TR0=1;    // 计数器T0运行
  }
   else
     {
     if(!S_Rate)
       {
               TR1=0;    // 定时器T1运行
               TR0=0;    // 计数器T0运行     
      delay(8);
      if(!S_Rate)
        {
      key++;
     if(key==40)
       {
        key=0; 
      ArtBeat=1;
       }
     }
               TR1=1;    // 定时器T1运行
               TR0=1;    // 计数器T0运行   
    }
     else
          key=0;
  }
 }
}
/********设置子程序************/
void Install(void)
{
  uchar i;
  uchar j;
  uchar FUHAOWEI;
  union{
        uchar p[4]; 
        float fbuf;
       }floa_data;
  FUHAOWEI=0;
  if(SetUp)    //判断是否进入设置状态
    {
   CLEAR();
   BZ=1;
   delay(3000);
   BZ=0;
   eeprom_eares(0x8000);
   while(!(S_Enter&S_Reduce));//判断Enter和-键是否已全部松开
   delay(5);
   while(!(S_Enter&S_Reduce));
   for(i=0;i<21;i++)  //进入设置状态,给每个值进行设置
      {
      add=0;
   switch(i)
      {
        case 0 : PD1=0;PD2=0;   PD3=0;   PD4=0;   break;
     case 1 : PD1=0;PD2=0;   PD3=0;   PD4=0x08;break;
     case 2 : PD1=0;PD2=0;   PD3=0x08;PD4=0;   break;
     case 3 : PD1=0;PD2=0x08;PD3=0;   PD4=0;   break;
     case 4 : PD1=0;PD2=0x08;PD3=0;   PD4=0;   break;
     case 5 : PD1=0;PD2=0x08;PD3=0;   PD4=0;   break;    
     case 6 : PD1=0;PD2=0x08;PD3=0;   PD4=0;   break;
     case 7 : PD1=0;PD2=0;   PD3=0;   PD4=0;   break;
     case 20: PD1=0;PD2=0;   PD3=0;   PD4=0x08;break;    
     default: PD1=0;PD2=0;   PD3=0x08;PD4=0;break;
      }
         while(S_Enter)
           {
        // 序号
     Writedata(86,Number[2*(i/10)]);
     Writedata(88,Number[2*(i/10)+1]);
     Writedata(90,Number[2*(i%10)]);
     Writedata(92,Number[2*(i%10)+1]);
        // 千位
     Writedata(110,Number[2*(abs(add+FirstValue[i])/1000)]);
     Writedata(112,PD2 | Number[2*(abs(add+FirstValue[i])/1000)+1]);
     //百位
     Writedata(114,Number[2*((abs(add+FirstValue[i])%1000)/100)]);
     Writedata(116,PD3 | Number[2*((abs(add+FirstValue[i])%1000)/100)+1]);
     //十位
     Writedata(118,Number[2*((abs(add+FirstValue[i])%100)/10)]);
     Writedata(120,PD4 | Number[2*((abs(add+FirstValue[i])%100)/10)+1]);
     //个位
     Writedata(122,Number[2*(abs(add+FirstValue[i])%10)]);
     Writedata(124,Number[2*(abs(add+FirstValue[i])%10)+1]);
       FUHAOWEI=((add+FirstValue[i])>>8)&0x80;
              if(FUHAOWEI==0x80)
                {
                   Writedata(106,0x02);
             Writedata(108,0x00);//万位显示负号
                }
              else
                {
                   Writedata(106,0x07);
             Writedata(108,0x06);//万位显示正号   
                }
        };
         while(!S_Enter);//ENTER即SW1键是否按下,按前消抖,松开时消抖
      delay(10);
      while(!S_Enter);
      switch(i)
        {
        case 0:
             {
         M_Num=(uchar)(add+FirstValue[0]);
         FirstValue[0]=add+FirstValue[0];
         eeprom_write(0x8000,M_Num); 
       }break;
      case 1:
             {
        set[i-1]=(float)(add+FirstValue[i])/10.0;
       FirstValue[i]=add+FirstValue[i];
       floa_data.fbuf=set[i-1];
       for(j=0;j<4;j++)
           eeprom_write(0x8001+j,floa_data.p[j]);
       }break;
      case 2:
             {
        set[i-1]=(float)(add+FirstValue[i])/100.0;
        FirstValue[i]=add+FirstValue[i];
       floa_data.fbuf=set[i-1];
       for(j=0;j<4;j++)
           eeprom_write(0x8005+j,floa_data.p[j]);
       }break;
      case 3:
             {
        set[i-1]=(float)(add+FirstValue[i])/1000.0;
       FirstValue[i]=add+FirstValue[i];
       floa_data.fbuf=set[i-1];
       for(j=0;j<4;j++)
           eeprom_write(0x8009+j,floa_data.p[j]);
       }break;
      case 4:
             {
          if(M_Num==2) 
           set[i-1]=(float)(add+FirstValue[i])/1000000.0;
       else if(M_Num==18)
               set[i-1]=(float)(add+FirstValue[i])/10000.0;
         else
                set[i-1]=(float)(add+FirstValue[i])/1000.0; 
       FirstValue[i]=add+FirstValue[i];                                 
       floa_data.fbuf=set[i-1];
       for(j=0;j<4;j++)
           eeprom_write(0x800d+j,floa_data.p[j]);
       };break;
      case 5:
             {
        set[i-1]=(float)(add+FirstValue[i])/1000.0;
        FirstValue[i]=add+FirstValue[i];
       floa_data.fbuf=set[i-1];
       for(j=0;j<4;j++)
          eeprom_write(0x8011+j,floa_data.p[j]);
       }break;
      case 6:
             {
        set[i-1]=(float)(add+FirstValue[i])/1000.0;
       FirstValue[i]=add+FirstValue[i];
       floa_data.fbuf=set[i-1];
       for(j=0;j<4;j++)
          eeprom_write(0x8015+j,floa_data.p[j]);
       }break;
      case 7:
             {
          MaxDistance=(uchar)(add+FirstValue[i]);
       FirstValue[i]=add+FirstValue[i];
       eeprom_write(0x8019,MaxDistance);
       }break;
      case 20:
             {
          JGTime=(float)(add+FirstValue[i])/10.0;
       FirstValue[i]=add+FirstValue[i];
       eeprom_write(0x8050,JGTime);
       }break;
      default:
             {
       if(i>7)
                        {
                       P_Time[i-8]=(float)(add+FirstValue[i])/100.0;
           FirstValue[i]=add+FirstValue[i];
                       floa_data.fbuf=P_Time[i-8];
                       for(j=0;j<4;j++)
                          eeprom_write(0x8020+j+4*(i-8),floa_data.p[j]);
                     }
       }break; 
     }
     BZ=1;
     delay(1000);
     BZ=0;
     }
   CLEAR();
 }
  SetUp=0;
}
/******************标定子程序***********************/
void Standardization(void)
{
  uchar i;
  float x1;
//  float x0;
  float y1;
  //float y0;
 // float xdata x2;
 // float xdata y2;
 // float xdata k1;
 // float xdata k2;
  uint  Bzero=0;
  union{
        uchar p[4];
        float fbuf;
       }floa_data;
  //y0=0;
  //zero=x;
  //x0=zero;     //取得零点频率和相应重量
  if(Standard)   //判断是否进入标定状态
 {
   BZ=1;
   delay(2000);
   Bzero=x;
   CLEAR();
   BZ=0;
   eeprom_eares(0x8200);
   while(!(S_Enter&S_Add)); // 判断SW1和SW2键是否已经全部松开
   delay(5);
   while(!(S_Enter&S_Add)); 
   add=600;
   while(S_Enter)     //取标准值,然后放入标准值砝码,并按ENTER即SW1键进行确定
        {              
          y1=add/10;
    //千位
    Writemdata(110,Number[2*(add/1000)]);
    Writemdata(112,Number[2*(add/1000)+1]);
    //百位
    Writemdata(114,Number[2*((add%1000)/100)]);
    Writemdata(116,Number[2*((add%1000)/100)+1]);
    //十位
    Writemdata(118,Number[2*((add%100)/10)]);
    Writemdata(120,0X08 | Number[2*((add%100)/10)+1]);
    //个位
       Writemdata(122,Number[2*(add%10)]);
    Writemdata(124,Number[2*(add%10)+1]);
    Writedata(80,0x01); //公斤
     };
   while(!S_Enter);
   delay(10);
   while(!S_Enter);
   delay(1000);
   x1=x;
   k=y1/(x1-Bzero);
   floa_data.fbuf=k;
   for(i=0;i<4;i++)
   {
     eeprom_write(0x8200+i,floa_data.p[i]);
      }
   BZ=1;
   delay(2000);
   CLEAR();
   BZ=0;
 }
  Standard=0;
  //b=-k*x0;
}
//*****************检测子程序*********************/
void CheckState(void)
{
 // uchar j;
  //uint  i; 
  int   Weiyi;
  uint data Weight;
//  uint  C_Num;
  //float Gmm;
  uint  Jzero;
  //j     =   0;
 // i     =   0;
  Weiyi =   0;
  Weight=   0;
 // C_Num =   0;
  //Gmm   =   0;
  Jzero =   0;
  if(Check)
    {
   delay(2000);
   BZ=0;
   delay(4000);
   Jzero=x;
   delay(1000);     
   CLEAR();
   while(1)
     {
  //***************检测设置值是否正确********************
   /* j=(uchar)(i/100);
    switch(j)
      {
     case 0 : C_Num=M_Num;break;          
     case 1 : C_Num=(uint)(set[0]*10);break;
     case 2 : C_Num=(uint)(set[1]*100);break;
     case 7 : C_Num=MaxDistance;break;
     default:
             {
         if(j<7)
        C_Num=(uint)(abs(set[j-1]*1000));
      else
        if(j<20)
           C_Num=(uint)(P_Time[j-8]*100);
        else
           C_Num=(uint)JGTime*10;
       };break;
   }
    delay(1);
    if((j/10)==0)
   Writedata(126,0x01);   //设置值序号小于10时,秒亮
    else
      if((j/10)==1)     //序号小于20,大于10时,瓦亮
     Writedata(126,0x02);
   else
     Writedata(126,0x04); //序号大于20时,次亮     
     
       //序号
    Writemdata(106,Number[2*(j%10)]);
    Writemdata(108,Number[2*(j%10)+1]);  //大数码管7
          //百位
    Writedata(82,Number[2*(C_Num/100)]);
    Writedata(84,Number[2*(C_Num/100)+1]);//小数码管4
          //十位
    Writedata(86,Number[2*((C_Num%100)/10)]);
    Writedata(88,Number[2*((C_Num%100)/10)+1]); //小数码管5
          //个位
    Writedata(90,Number[2*(C_Num%10)]);
    Writedata(92,Number[2*(C_Num%10)+1]); //小数码管6
    i++;
    if(i==2099)
      i=0;    
      *///*********************检测重块重量**************************
    WorkWeight=(int)((k*(x-Jzero))*10.0+0.5);
    //if(abs(WorkWeight-WorkWeightZero)<4)
    //   WorkWeight=WorkWeightZero;
    ////if(x    //if(x    if((WorkWeight<10) || (WorkWeight>3000))
       {
     WorkWeight=0;
 //    Jzero=x;
    }
    Weight=(uint)WorkWeight;
    //Weight=x;
         //万位
    Writedata(106,Number[2*(Weight/10000)]);
    Writedata(108,Number[2*(Weight/10000)+1]);
         //千位
    Writedata(110,Number[2*((Weight%10000)/1000)]);
    Writedata(112,Number[2*((Weight%10000)/1000)+1]);
         //百位
    Writedata(114,Number[2*((Weight%1000)/100)]);
    Writedata(116,Number[2*((Weight%1000)/100)+1]);
         //十位
    Writedata(118,Number[2*((Weight%100)/10)]);
    Writedata(120,0x08 | Number[2*((Weight%100)/10)+1]);
         //个位
    Writemdata(122,Number[2*(Weight%10)]);
    Writemdata(124,Number[2*(Weight%10)+1]);
    Writedata(80,0x01);
//    WorkWeightZero=WorkWeight;     
       //************************检测位移********************************
    Weiyi=Gear*0.59032;
    if(Weiyi<0)
       Weiyi=0;
       Writedata(94,Number[2*(Weiyi/100)]);
    Writedata(96,Number[2*(Weiyi/100)+1]);
          Writedata(98,Number[2*((Weiyi%100)/10)]);
       Writedata(100,Number[2*((Weiyi%100)/10)+1]);
          Writedata(102,Number[2*(Weiyi%10)]);
       Writedata(104,Number[2*(Weiyi%10)+1]);
     if(!Check)
          break;
  }
   CLEAR();
   delay(1000);
   BZ=0;
 } 
}
/**************心率检测子程序*******************/
void HeartRate(void)
{
  bit   ArtBeatOut;
  uint  hr;
  uchar PD5;
  uchar ge;
  uchar shi;
  uchar bai;
  uint  BZNumber;
  ge           =   0;
  shi          =   0;
  bai          =   0;
  hk0          =   0;
  hk1          =   0;
  hflag        =   0;
  hhflag       =   0;
  hr           =   0;
  PD5          =   0;
  BZNumber     =   0;
  H_Rate       =   0;
  HRateTime    =   0;
  HRateNumber  =   0;
  ZeroHRateTime=   0;
  ArtBeatOut   =   0;
//  while(!S_Rate)
//    {
//   delay(500);
//   hr++;
//   if(hr==8)
//     ArtBeat=~ArtBeat;
//   else
//     if(hr>=20)  //10S后
//       {
//   BZ=1;
//   zero=x;
//   ArtBeat=~ArtBeat;
//   delay(3000);
//   BZ=0;
//   delay(3000);
//   BZ=1;
//   delay(3000);
//   BZ=0;       
//    }     
// }
//  hr=0;
  if(ArtBeat)
    {      
   ET0=0;//关定时器012的中断,并关掉定时器12和计数器0
      ET1=0; 
      TR0=0;
      TR1=0;
      EX0=0;//关外部中断0,下降沿触发
      IT0=0;
   EX1=1;//开外部中断1,下降沿触发
      IT1=1;
   CLEAR();
   delay(1000);
   BZ=1;
   delay(1000);
   BZ=0; 
   ArtBeatOut=1;
      while(1)
           {
    if(Heart)
             PD5=0;
          else
             PD5=0x08;
    //if(H_Rate>160)
      //H_Rate=160;
    ge=2*(H_Rate%10);
    shi=2*((H_Rate%100)/10);
    bai=2*(H_Rate/100);
    if(H_Rate>9)
      {
      //十位
         Writedata(118,Number[shi]);
         Writedata(120,Number[shi+1]); 
      if(H_Rate>99)
        {
           //百位
              Writedata(114,Number[bai]);
              Writedata(116,Number[bai+1]);     
     }
      else
        {
           //百位
              Writedata(114,0);
              Writedata(116,0);       
     }
             
      }
    else
      {
         //十位
         Writedata(118,0);
         Writedata(120,0); 
      //百位
         Writedata(114,0);
         Writedata(116,0);            
      }        
     //个位
    Writedata(122,Number[ge]);
    Writedata(124,PD5 | Number[ge+1]);

    Writedata(126,0x04);
    if(BZ)
      {
        BZNumber++;
     if(BZNumber==300) 
       {
         BZ=0;
      BZNumber=0;
       }   
      }
   //判断是否退出心率检测
    while(!S_Rate)
       {
       delay(300);
       hr++;
       if(hr==2)
 //        ArtBeat=~ArtBeat;
                  ArtBeatOut=0;        
    }
    hr=0;
             if(!ArtBeatOut)
             break;   
           }
   ArtBeat=0;
   BZ=1;
   delay(1000);
   BZ=0;
   CLEAR();
   Writedata(94,0x0f);Writedata(96,0x01);
      Writedata(98,Number[2*(M_Num/10)]);
   Writedata(100,Number[2*(M_Num/10)+1]);
      Writedata(102,Number[2*(M_Num%10)]);
   Writedata(104,Number[2*(M_Num%10)+1]);
      Writedata(82,0x07);Writedata(84,0x03); 
      Writedata(86,0x0d);Writedata(88,0x07);
   Writedata(90,Number[2*P_Num]);
   Writedata(92,Number[2*P_Num+1]);
      EX0=1;//开外部中断0,下降沿触发
      IT0=1;
      ET0=1;//开定时器012的中断,并打开定时器12和计数器0
      ET1=1; 
      TR0=1;
      TR1=1;
  
    }
}
/*************工作状态子程序*****************/
void WorkState(void)
{
  uchar i         =  0;
  uchar ge        =  0;
  uchar shi       =  0;
  uchar bai       =  0;
  uchar qian      =  0;
  uchar wai       =  0;
  uint  WorkTime  =  0;
 // Wzero           =  0;
  W_weight0       =  0;
  W_weight1       =  0;
  //hflag=0;
//  PNumber0         =  0;
//  PNumber1         =  0;
  Exercise         =  0;  
  TimeNumber       =  0;
  WorkWeight       =  0;
  WorkOverTime     =  0;
  WorkCounter      =  0;
  WorkPower        =  0;
//  WorkWeight=0;
  WorkEnergy       =  0;
//  WorkEnergyZero   =  0;
  MaxGear          =  0;
  MinGear          =  0;
//UpMinGear=0;
  RedStartTime     =  0;
  RedStartTimeZero =  0;
  RedUpTime        =  0;
  WaveDisplayTime  =  0;
  WaveDisplaySignal=  0;
  XNumber          =  0;
  WorkOut0         =  0;
 // WorkOut0=0;
        
  if(Gear<6)
    Operating=0;
  else
    Operating=1;
  if(Operating)
    {
   Writedata(126,0x01); //单位符号-秒
   //显示5秒倒计时
   for(i=5;i>0;i--)
      {
     BZ=~BZ;
//         Writedata(118,0x0d);
//        Writedata(120,0x07);    
           Writedata(122,Number[2*i]);
        Writedata(124,Number[2*i+1]);
           delay(1000);
   }
       BZ=0;   
    //开始进入锻炼模式
   // delay(1000);
    Exercise=1;
       Wzero=x;
   // b=k*Wzero;
    Gear=0;
    while(1)
      {  
           
     //显示锻炼重量,单位-公斤,最大显示重量为999.9公斤
     WaveDisplaySignal=1;
           while(WaveDisplaySignal)
             { 
       HeartRate();
                   Writedata(126,0x00);
                   Writedata(80,0x01); //单位符号-公斤
       ge   =   2*(WorkWeight%10);
       shi  =   2*((WorkWeight%100)/10);
       bai  =   2*((WorkWeight%1000)/100);
       qian =   2*((WorkWeight%10000)/1000);
       wai  = 2*(WorkWeight/10000);
       if(WorkWeight>99)
         {
                  //百位
                     Writedata(114,Number[bai]);
                     Writedata(116,Number[bai+1]);
      if(WorkWeight>999)
        {
                       //千位
                          Writedata(110,Number[qian]);
                          Writedata(112,Number[qian+1]); 
        if(WorkWeight>9999)
          {
                 //万位
                             Writedata(106,Number[wai]);
                             Writedata(108,Number[wai+1]);     
          }
        else
          {
             //万位
                Writedata(106,0);
                            Writedata(108,0);        
          }        
        }
      else
        { 
           //万位
           Writedata(106,0);
                       Writedata(108,0);
        //千位
        Writedata(110,0);
                          Writedata(112,0);
        }      
      }
          else
         {
      //万位
      Writedata(106,0);
                  Writedata(108,0);
      //千位
      Writedata(110,0);
                     Writedata(112,0);
      //百位
                     Writedata(114,0);
                     Writedata(116,0);           
      }
             //十位
                Writedata(118,Number[shi]);
                Writedata(120,0x08 | Number[shi+1]);
             //个位
                Writedata(122,Number[ge]);
                Writedata(124,Number[ge+1]);
           WaveDisplay();//显示位移波形
          }
   
     // 显示锻炼时间,单位-秒,最大显示时间为99999秒
     WaveDisplaySignal=1;
           while(WaveDisplaySignal)
             { 
       HeartRate();
             WorkTime=TimeNumber/50;
                   Writedata(80,0x00);
                   Writedata(126,0x01); //单位符号-秒
       ge   =   2*(WorkTime%10);
       shi  =   2*((WorkTime%100)/10);
       bai  =   2*((WorkTime%1000)/100);
       qian =   2*((WorkTime%10000)/1000);
       wai  = 2*(WorkTime/10000);
       if(WorkTime>9)
         {
                  //十位
                     Writedata(118,Number[shi]);
                     Writedata(120,Number[shi+1]);
      if(WorkTime>99) 
        {
                       //百位
                          Writedata(114,Number[bai]);
                          Writedata(116,Number[bai+1]);
        if(WorkTime>999)
          {
                //千位
                               Writedata(110,Number[qian]);
                               Writedata(112,Number[qian+1]);
          if(WorkTime>9999) 
            {
                        //万位
                                 Writedata(106,Number[wai]);
                                 Writedata(108,Number[wai+1]);       
         }
          else
            {
               //万位
                     Writedata(106,0);
                                 Writedata(108,0);         
         }    
          }
        else
          {
          //万位
                Writedata(106,0);
                            Writedata(108,0);
                //千位
                Writedata(110,0);
                               Writedata(112,0);    
          }       
        }
      else
        {
           //万位
          Writedata(106,0);
                      Writedata(108,0);
           //千位
          Writedata(110,0);
                         Writedata(112,0);
           //百位
                         Writedata(114,0);
                         Writedata(116,0);       
        }    
      }
       else
         {
      //万位
      Writedata(106,0);
                  Writedata(108,0);
      //千位
      Writedata(110,0);
                     Writedata(112,0);
      //百位
                     Writedata(114,0);
                     Writedata(116,0);
                  //十位
                     Writedata(118,0);
                     Writedata(120,0);           
      }
             //个位
                Writedata(122,Number[ge]);
                Writedata(124,Number[ge+1]);
           WaveDisplay();//显示位移波形
          }
     //显示锻炼功率,单位-瓦,最大显示功率为9999.9瓦
     WaveDisplaySignal=1;
           while(WaveDisplaySignal)
             {
       HeartRate();
                   Writedata(80,0x00);
                   Writedata(126,0x02); //单位符号-瓦
       if((ulong)WorkPower>99999)
         WorkPower=99999;
        ge   =   2*((ulong)WorkPower%10);
       shi  =   2*(((ulong)WorkPower%100)/10);
       bai  =   2*(((ulong)WorkPower%1000)/100);
       qian =   2*(((ulong)WorkPower%10000)/1000);
       wai  = 2*((ulong)WorkPower/10000);
       if((ulong)WorkPower>99)
         {
                  //百位
                     Writedata(114,Number[bai]);
                     Writedata(116,Number[bai+1]);
      if((ulong)WorkPower>999)
        {
                       //千位
                          Writedata(110,Number[qian]);
                          Writedata(112,Number[qian+1]); 
        if((ulong)WorkPower>9999)
          {
                            //万位
                            Writedata(106,Number[wai]);
                            Writedata(108,Number[wai+1]);          
          }
        else
          {
                //万位
                Writedata(106,0);
                            Writedata(108,0);         
          }      
        } 
      else
        {
           //万位
           Writedata(106,0);
                       Writedata(108,0);
           //千位
           Writedata(110,0);
                          Writedata(112,0);       
        }    
      }
       else
         {
      //万位
      Writedata(106,0);
                  Writedata(108,0);
      //千位
      Writedata(110,0);
                     Writedata(112,0);
      //百位
                     Writedata(114,0);
                     Writedata(116,0);     
      }
             //十位
                Writedata(118,Number[shi]);
                Writedata(120,0x08 | Number[shi+1]);
             //个位
                Writedata(122,Number[ge]);
                Writedata(124,Number[ge+1]);
           WaveDisplay();//显示位移波形
          }
     //显示锻炼次数,单位-次,最大显示次数为999次
     WaveDisplaySignal=1;
           while(WaveDisplaySignal)
             {
       HeartRate();
                   Writedata(80,0x00);
                   Writedata(126,0x04); //单位符号-次
       ge   =   2*(WorkCounter%10);
       shi  =   2*((WorkCounter%100)/10);
       bai  =   2*((WorkCounter%1000)/100);
       qian =   2*((WorkCounter%10000)/1000);
       wai  = 2*(WorkCounter/10000);
       if(WorkCounter>9)
         {
                  //十位
                     Writedata(118,Number[shi]);
                     Writedata(120,Number[shi+1]);
      if(WorkCounter>99) 
        {
                       //百位
                          Writedata(114,Number[bai]);
                          Writedata(116,Number[bai+1]);
        if(WorkCounter>999)
          {
                //千位
                               Writedata(110,Number[qian]);
                               Writedata(112,Number[qian+1]);
          if(WorkCounter>9999) 
            {
                        //万位
                                 Writedata(106,Number[wai]);
                                 Writedata(108,Number[wai+1]);       
         }
          else
            {
               //万位
                     Writedata(106,0);
                                 Writedata(108,0);         
         }    
          }
        else
          {
          //万位
                Writedata(106,0);
                            Writedata(108,0);
                //千位
                Writedata(110,0);
                               Writedata(112,0);    
          }       
        }
      else
        {
           //万位
          Writedata(106,0);
                      Writedata(108,0);
           //千位
          Writedata(110,0);
                         Writedata(112,0);
           //百位
                         Writedata(114,0);
                         Writedata(116,0);       
        }    
      }
       else
         {
      //万位
      Writedata(106,0);
                  Writedata(108,0);
      //千位
      Writedata(110,0);
                     Writedata(112,0);
      //百位
                     Writedata(114,0);
                     Writedata(116,0);
                  //十位
                     Writedata(118,0);
                     Writedata(120,0);           
      }
             //个位
                Writedata(122,Number[ge]);
                Writedata(124,Number[ge+1]);
           WaveDisplay();//显示位移波形
          }
     //显示锻炼热量,单位-千卡,最大显示功率为999.99千卡
     WaveDisplaySignal=1;
           while(WaveDisplaySignal)
             {
       HeartRate();
                   Writedata(80,0x00);
                   Writedata(126,0x08); //单位符号千卡
       ge   =   2*((ulong)WorkEnergy%10);
       shi  =   2*(((ulong)WorkEnergy%100)/10);
       bai  =   2*(((ulong)WorkEnergy%1000)/100);
       qian =   2*(((ulong)WorkEnergy%10000)/1000);
       wai  = 2*((ulong)WorkEnergy/10000);
       if((ulong)WorkEnergy>999)
         {
                  //千位
                     Writedata(110,Number[qian]);
                     Writedata(112,Number[qian+1]);
      if((ulong)WorkEnergy>9999)
        {
                       //万位
                       Writedata(106,Number[wai]);
                       Writedata(108,Number[wai+1]);       
        }
      else
        {
          //万位
          Writedata(106,0);
                      Writedata(108,0);       
        }      
      }
       else
         {
      //万位
      Writedata(106,0);
                  Writedata(108,0);
      //千位
      Writedata(110,0);
                     Writedata(112,0);     
      }
             //百位
                Writedata(114,Number[bai]);
                Writedata(116,0x08 | Number[bai+1]);
             //十位
                Writedata(118,Number[shi]);
                Writedata(120,Number[shi+1]);
             //个位
                Writedata(122,Number[ge]);
                Writedata(124,Number[ge+1]);
           WaveDisplay();//显示位移波形
          }
/**********************************************************
   Writedata(0x0018,SmallNumber[2*(UpDistance/100)]);
   Writedata(0x001c,SmallNumber[2*(UpDistance/100)+1]);
      Writedata(0x0020,SmallNumber[2*((UpDistance%100)/10)]);
   Writedata(0x0024,SmallNumber[2*((UpDistance%100)/10)+1]);
      Writedata(0x0028,SmallNumber[2*(UpDistance%10)]);
   Writedata(0x002c,SmallNumber[2*(UpDistance%10)+1]);
      Writedata(0x0000,SmallNumber[2*(UpTimer/100)]);
   Writedata(0x0004,SmallNumber[2*(UpTimer/100)+1]); 
      Writedata(0x0008,SmallNumber[2*((UpTimer%100)/10)]);
   Writedata(0x000c,SmallNumber[2*((UpTimer%100)/10)+1]);
   Writedata(0x0010,SmallNumber[2*(UpTimer%10)]);
   Writedata(0x0014,SmallNumber[2*(UpTimer%10)+1]);
*******************************************************/
     //判断锻炼是否结束,结束则退出工作模式,进入初始化模式
  if((WorkOut0==1))
       {
//     ArtBeat=1;
                CLEAR();
    Gear=0;
          break;
    }   
     if(WorkOverTime>6000)
       {
//     ArtBeat=1;
                CLEAR();
    Gear=0;
          break;
    }
   }
 }
}
/***************点阵图子程序*******************/
void WaveDisplay(void)
{
  uchar i;
  uchar j;
  uint  PictureElement;
  uint  ProgramTime;
  int  ProgramDistance;
  int  W_weight;
//  int  idata W_weight1;
  i=0;
  j=0;
  W_weight=0;
  PictureElement=0;
  ProgramTime=0;
  ProgramDistance=0;
 // if(W_weight0<200)
  //  hflag=9;
  //else
 //   hflag=16;
  W_weight1=(int)((k*(Wzero-x))*10+0.5);
  //W_weight1=(int)(10*b-10*k*x+0.5);
  if((W_weight1>20) && (W_weight1<3000))
    {
   //if(W_weight0!=0)
    // {
     ////if((W_weight1>W_weight0)&&(W_weight1    // if((WorkCounter==0) && (MaxGear>Gear) /*&& (MaxGear      // {
      //   W_weight0=W_weight1;
          //  W_weight=W_weight0;   
   // }
    // else
     // {
     if((MaxGear>Gear+3) && (W_weight0==0))
        W_weight0=W_weight1;
     W_weight=W_weight0;
  // }         
  //}
  // else
     //{
    // W_weight0=W_weight1;
     //W_weight=W_weight0;
  //}    
 }
  else
    {
      W_weight=0;
   if(WorkCounter>0)
     {
        if(RedUp)
   //if(Gear<(MaxDistance/2))
           Gear=0;
        else
        if(Gear<9)
        Gear=0;  
  }
//   Wzero=x;  
 }
  //if(((Wzero-x)>60) && ((Wzero-x)<60000))
   // {
   //   hflag++;
 //  if(hflag==150)
 //    {
  //     W_weight0=(int)((k*(Wzero-x))*10.0+0.5);  
 // } 
  // if(hflag>222)
  //   hflag=152;
  // W_weight=W_weight0;
 //}
  //else
    //W_weight=0;
    
 //   hflag=0;      
 
  //if((W_weight<3) || (W_weight>3000))
// {
//   W_weight=0;
//   if(W_weight>-3)
//     {
 //       Wzero=x;
 //   Wzero0=Wzero;  
//  }
//   else
//       Wzero=Wzero0;
    
// }
  //WorkWeight=W_weight;             
  WorkWeight=(uint)(W_weight*set[1]+set[0]*10+0.5);
  if(P_Num==1)
    {
   ProgramDistance=Gear*0.59032+0.5;
   if(ProgramDistance<0)
     ProgramDistance=0;
   if(ProgramDistance     PictureElement=ProgramDistance*25/MaxDistance;
      else
     PictureElement=24;
   if(PictureElement==0)
     {
    for(i=0;i<25;i++)
       {
               Writemdata(2*i,0);
      Writedata(79+2*i,0);    
    }
  }
   else
     {
    if(PictureElement==24)
      {
         for(i=0;i<25;i++)
         {
                    Writemdata(2*i,0xfe);
     Writedata(79+2*i,0x0e);      
      }  
   }
    else
      {
         for(i=0;i<=PictureElement;i++)
         {
              Writemdata(48-2*i,0xfe);
     Writedata(79+2*i,0x0e);     
      }
            PictureElement=24-PictureElement;
            for(i=0;i         {
              Writemdata(2*i,0);
     Writedata(127-2*i,0);           
      }       
   }  
  }      
 }
  else
    {
   if(TimeNumber<20)
     {
       Time20=0;
    for(i=0;i<25;i++)
       {
                   Writemdata(2*i,0);
       Writedata(79+2*i,0);    
    }  
     }
   else
     {
//       if(Time20==30)
       Time20=1;
     }
   if(Time20==1)
     {  
   j=P_Num*3-6;
   ProgramTime=TimeNumber-19-XNumber*((50*(P_Time[j]+P_Time[j+1]+P_Time[j+2]))+(JGTime*50));
         if((ProgramTime*2)<(100*P_Time[j]))
     {
    PictureElement=(ProgramTime*50)/(100*P_Time[j]);
       if(PictureElement==24)
         {
           for(i=0;i<25;i++)
     Writedata(2*i+79,0x0f);       
      }
       else
         {
           for(i=0;i<=PictureElement;i++)
        Writedata(2*i+79,0x0f);     
              PictureElement=24-PictureElement;
              for(i=0;i        Writedata(127-2*i,0);           
      } 
     }
   else
     {     
    if((ProgramTime*2)<=(100*(P_Time[j]+P_Time[j+1])))
      {           
      for(i=0;i<25;i++)
      Writedata(79+2*i,0x0f);     
      }
    else
      {
     if(ProgramTime<(50*(P_Time[j]+P_Time[j+1]+P_Time[j+2])))
       {  
      PictureElement=(ProgramTime-50*(P_Time[j]+P_Time[j+1]))/(2*P_Time[j+2]);
               if(PictureElement==0)
                 {
                    for(i=0;i<25;i++) 
        Writedata(79+2*i,0x0f);        
              }
               else
                 {
                    for(i=0;i<=PictureElement;i++)
          Writedata(127-2*i,0);       
                       PictureElement=24-PictureElement;
                       for(i=0;i          Writedata(2*i+79,0x0f);               
              }
     }
      else
     {
             for(i=0;i<25;i++)
        Writedata(2*i+79,0);      
       if(ProgramTime>=((50*(P_Time[j]+P_Time[j+1]+P_Time[j+2]))+(JGTime*50)))
         XNumber++;      
     }            
    }
   } 
 /******************************************************************** 
   if(RedStartTime!=0)
  {
   if(RedStartTimeZero!=RedStartTime)
     {
    for(i=0;i<50;i++)
                Writedata(0x0060+i*4,0x00);  
     }
   RedStartTimeZero=RedStartTime;
   ProgramTime=TimeNumber-RedStartTime;
   if(WorkWeight<300)
      PNumber=0x03;   
    else
      if(WorkWeight<600)
     PNumber=0x07;
   else
     PNumber=0x0f;   
   j=(P_Num-2)*3;
         if((ProgramTime*2)<(100*P_Time[j]))
     {
    PictureElement=(ProgramTime*50)/(100*P_Time[j]);
       for(i=0;i    {
               Writedata(0x0060+i*4,PNumber);
            Writedata(0x0124-i*4,PNumber);     
    }
          PictureElement=24-PictureElement;
          for(i=0;i    {
               Writedata(0x00c0-i*4,0);
            Writedata(0x00c4+i*4,0);     
    } 
     }
   else
     {     
    if((ProgramTime*2)<=(100*(P_Time[j]+P_Time[j+1])))
      {           
      for(i=0;i<50;i++)
                     Writedata(0x0060+i*4,PNumber);
      delay(200); 
      }
    else
      {
     if(ProgramTime<(50*(P_Time[j]+P_Time[j+1]+P_Time[j+2])))
       {  
      PictureElement=((ProgramTime-50*(P_Time[j]+P_Time[j+1]))*50)/(100*P_Time[j+2]);
      for(i=0;i      {
        Writedata(0x00c0-i*4,0);
        Writedata(0x00c4+i*4,0);          
      }
      PictureElement=24-PictureElement;
      for(i=0;i      {
        Writedata(0x0060+i*4,PNumber);
        Writedata(0x0124-i*4,PNumber);
      }
     }
      else
     {
             for(i=0;i<50;i++)
                         Writedata(0x0060+i*4,0x00);      
     }            
    }
   }                                 
  }
****************************************/
  }
  // ProgramDistance=(uint)(((abs(Gear)*3.14*4.7)/25)+0.5);
   ProgramDistance=Gear*0.59032+0.5;
   if(ProgramDistance<0)
     ProgramDistance=0;
   if(ProgramDistance     PictureElement=ProgramDistance*25/MaxDistance;
      else
     PictureElement=24;
   if(PictureElement==0)
     {
    for(i=0;i<25;i++)
               Writemdata(2*i,0);   
  }
   else
     {
    if(PictureElement==24)
      {
         for(i=0;i<25;i++)
                  Writemdata(2*i,0x3c); 
   }
    else
      {
         for(i=0;i<=PictureElement;i++)
            Writemdata(48-2*i,0x3c);
            PictureElement=24-PictureElement;
            for(i=0;i              Writemdata(2*i,0);                  
   }  
  }   
 }
}
void redweiyi(void)
{
  uchar MMGear;
  uint  MMTime;
  if(Left)
    {
   Gear--;
      if(Gear<6)
   Gear=0;     
 }
  else
    {
   Gear++; 
 }
  if(Exercise)
    {
      if(RedUp)
        {
       if(MaxGear         {
        MaxGear=Gear;
           RedUpTime=TimeNumber;  
      }
       if(MaxGear-Gear==18)
         {        
     WorkCounter++;
     if((WorkCounter==1) && (W_weight0==0))
     W_weight0=W_weight1;
     MMGear=MaxGear-MinGear;
     if(MaxGear        MMGear=0;      
     MMTime=RedUpTime-RedStartTime;
     WorkEnergy+=set[2]*MMTime*2
       +set[3]*MMGear*59.032
      +set[4]*WorkWeight*10  
                 +set[5]*100;
      if((uint)WorkEnergy>65530)
        WorkEnergy=0;
     //WorkEnergy=WorkEnergy+WorkEnergyZero;
     MMTime=TimeNumber-RedStartTime;
     if(MMTime==0)
       MMTime=1;
     //WorkPower=WorkWeight*MMGear*2.892568/MMTime;
   //  =WorkPower;
     WorkPower=((((WorkWeight/10.0)*9.8*((MMGear*3.14*4.7)/25.0))
              /(100.0*MMTime/50.0))+0.05)*10;
     //WorkEnergy=MMGear;
     if(WorkPower>99999)
       WorkPower=99999;           
     MinGear=Gear;
     RedUp=0;
        //WorkCounter++;
      }
    if(Gear<6)
      RedUp=0;
     }
      if(!RedUp)
        {
       if(MinGear>Gear)
          MinGear=Gear;
       if(Gear<=0)
         MinGear=0;
       if((Gear-MinGear)>5)
         {
        RedUp=1;
        MaxGear=0;
           RedStartTime=TimeNumber;
      }
        } 
 }  
}
/******************************************/
//
//
//
//
/*********************************************/
void Int_0(void) interrupt 0
{
   redweiyi();
}
void Timer0(void) interrupt 1   //频率计数
{
   TH0=0;
   TL0=0;
   count++;
}
void Int_1(void) interrupt 2       //心率计数
{
   HRateNumber++;
   if(HRateNumber==2)
  {
     HRateNumber=1;
  hk0=3000/(HRateTime-ZeroHRateTime);
        if((hk0>50) && (hk0<150))
       {
                hhflag++;
    hk1+=hk0;   
    }
  }
   if(HRateNumber==1)
     {
  ZeroHRateTime=HRateTime; 
  }
   if(hhflag==10)
  {
    
  hhflag=0;
  H_Rate=hk1/10;
  hk1=0;
  hk0=0;
  }
}
void Timer1(void) interrupt 3
{            // 均值滤波,取得频率
   TH1=(65536-50000)/256;
   TL1=(65536-50000)%256;
   Fvalue++;
   if(Fvalue==4)
     {
       Fvalue=0;
       x=count*65536+TH0*256+TL0;
       count=0;
       TH0=0;
       TL0=0;
      }
}
void Timer2(void) interrupt 5
{                   //对键盘进行定时扫描
  TF2=0;
//  if(Gear-Gear0>10)
 //   Gear=0;
  if((Exercise==1) && (ArtBeat==0) )
    {
      TimeNumber++; 
   if(Gear<6)
     WorkOverTime++;
   else
     WorkOverTime=0;
  if(WaveDisplaySignal)
   {
  WaveDisplayTime++;
  if(WaveDisplayTime==150)
    {
       WaveDisplaySignal=0;
    WaveDisplayTime=0;
    }               
   }
 }
 // Gear0=Gear;
  if(ArtBeat)
 HRateTime++;
  if(!ArtBeat) 
    KeyBoard(); //对键盘进行定时扫描 
}
阅读(1324) | 评论(0) | 转发(0) |
0

上一篇:proteus对照表

下一篇:原理图_普中科技

给主人留下些什么吧!~~