第一篇BLOG...随便写写...

/***********************www.3ctest.com*******************************************
* 文 件 名           : main.c
* 作    者           : Zongping.Liu
* 公    司           : 苏州泰思特电子科技有限公司
* 版    本           : V1.0
* 完成日期           : 07/18/2009
* 功能描述           : SG_5006 全自动雷击浪涌发生器功能模块实现
* 版本增加           :
********************************************************************************/
#include "main.h"
main()
{
   DeviceInit();
   IOInit();
   ParaInit();   
   while(1)        
  {
 //  float Vtemp_sensor =  AD_Value[0] * 3.3 / 0xfff;
 //  float Current_Temp =  GetTemp(AD_Value[1]); //(1.43 - Vtemp_sensor)/0.0043 + 25;
    protect();
    TCH_Process();
    if(Run_All_Flag)//按下了开始键,或者,实验次数未到
    {
      Run_All_Flag=FALSE; 
   //   Tim3_Delay_1ms(100);
      Do_Process();
    }
   if(All_Stop_Flag) //按下了停止键或者试验次数到.停止整个试验
    {
      Real_IntnumTestTimes=0;
      DA_Flag=FALSE;
      All_Stop_Flag=FALSE;
      DA(0);
      IOInit();
    }
   if(DA_Flag)
   {
      DA(1);
   }
    if(DA_Complete_Flag)//充电完成
    {
      DA_Complete_Flag=FALSE;
      Systick_Delay_1ms(1);//加十分之一充电时间延时
      DAC_SetChannel1Data(DAC_Align_12b_R,0);
      Systick_Delay_1ms(10);//delay 10ms 
      GPIO_WriteBit(GPIOA,GPIO_Pin_8,(BitAction)(1)); //打开P8开关  主开关闭合
      Systick_Delay_1ms(10);  //delay 10ms         //10ms 的主开关触发脉冲
      GPIO_WriteBit(GPIOA,GPIO_Pin_8,(BitAction)(0));               //DAC 清零
      Systick_Delay_1ms(500);//延时500ms       //延时0.5S
      GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1)); //闭合PB5=1开关  充电电容开始放电
      Real_IntnumTestTimes++;
      if(Real_IntnumTestTimes<=IntnumTestTimes)
      {
        if(Bmp_ID == 1)   DisplayOnBmp(1);
        if ( Real_IntnumTestTimes == IntnumTestTimes )  Run_All_Flag=FALSE;
       // Systick_Delay_1ms(IntnumTestInterval*1000);
         SysTick_CounterCmd(SysTick_Counter_Enable); // 使能SysTick计数器
         TimingDelay = IntnumTestInterval*1000; // 读取延时时间
      }
    }
   if(TimingDelay == 0 && Run_All_Flag == FALSE && Real_IntnumTestTimes > 0 && Real_IntnumTestTimes < IntnumTestTimes ) // 判断延时是否结束
  {
   Run_All_Flag=TRUE;
   SysTick_CounterCmd(SysTick_Counter_Disable); // 关闭SysTick计数器
   SysTick_CounterCmd(SysTick_Counter_Clear); // 清除SysTick计数器
  }   
  }
}

void TxEOF(void)
{
  SendChar(0xcc);
  SendChar(0x33);
  SendChar(0xc3);
  SendChar(0x3c);
}
void TxWord(u16 n)
{
  u8 H,L; 
   H =n>>8;
   L =n;
   SendChar(H); //高位在前低位在后
   SendChar(L);
 
}   
void Display(u16 x,u16 y,char n)    //  显示单个ASCII字符
{
   SendChar(0xAA);
   SendChar(0x55);//  16*16点阵字体
   TxWord(x);//显示位置的x,y坐标
   TxWord(y);
   SendChar(0x30+n);
   TxEOF();
}

void DisplayError(int x,int y,int n)  //出错提示  全部归零
{ int i;
for(i=0;i{
 SendChar(0xAA);SendChar(0x55);TxWord(x);TxWord(y);SendChar(0x30+0x00);TxEOF();
 x=x+16*i;
 }
}
 
void DisplayNum(int x,int y,int n) //LCD显示按下的数字
 {
   SendChar(0xAA);SendChar(0x40);SendChar(0xF8);SendChar(0x00);SendChar(0xFF);SendChar(0xFF); TxEOF(); //设置当前调色板颜色.背景白色,前景红色
   SendChar(0xAA);SendChar(0x55);TxWord(x);TxWord(y);SendChar(0x30+ n);TxEOF(); 
   /*  SendChar(0xAA);SendChar(0x71);SendChar(0x03);
     switch (bmpID)
     {
     case 111:TxWord(0x0085);TxWord(0x0031);TxWord(0x00F2);TxWord(0x0055);break;
     case 112:TxWord(0x0085);TxWord(0x005A);TxWord(0x00F2);TxWord(0x007E);break;
     case 113:TxWord(0x0085);TxWord(0x0086);TxWord(0x00F2);TxWord(0x00AA);break;
     case 114:TxWord(0x0085);TxWord(0x00AD);TxWord(0x00F2);TxWord(0x00D4);break;
     case 115:TxWord(0x0085);TxWord(0x00D9);TxWord(0x00F2);TxWord(0x0100);break;
     default:break;
     }
     TxEOF(); 
      SendChar(0xAA);SendChar(0x98);
       switch (bmpID)
     {
     case 111:TxWord(DispTestHV_x);TxWord(DispTestHV_y);break;
     case 112:TxWord(DispTestTimes_x);TxWord(DispTestTimes_y);break;
     case 113:TxWord(DispTestInterval_x);TxWord(DispTestInterval_y);break;
     case 114:TxWord(DispTestGrade_x);TxWord(DispTestGrade_y);break;
     case 115:TxWord(DispTestphasic_x);TxWord(DispTestphasic_y);break;
     default:break;
     }
      SendChar(0x00);SendChar(0x82);SendChar(0x03);TxWord(0xF800);TxWord(0xFFFF);
      SendChar(n);
      TxEOF();*/
     
    

void LumenControl(int n)//LCD 的流明度控制
{
  switch(n)
  {
  case 0: SendChar(0xAA);SendChar(0x5F);SendChar(0x1E); TxEOF();break;//暗
  case 1: SendChar(0x00);SendChar(0x82);SendChar(0x3F); TxEOF();break;//亮
  default:break;
  }
}

void DA(int n)
{ DAC_TypeDef DAC1_TypeDef;
    float a=0;
 //   u16 b=0;
    u16 DA_value;
   if(n==0)
   {
     DAC_SetChannel1Data(DAC_Align_12b_R,0);
   }
   else if(n==1) //做DA增压
     {
         Tim2_EnableTIMBASE();                                        //定时器Tim2的四个通道计数初值的设定
  DA_value=IntnumHV*4095/Umax; //充电函数
  if(AD_count<=0.7*AD_TimeSet)//7S=10S*70%.每次1ms加一,所以要加7000次        
  {
   a=(AD_count)*(DA_value)*0.9/(0.7*AD_TimeSet);
   }
  else a=0.9*((float )DA_value)+(((float)AD_count-(0.7*(float)AD_TimeSet)))*((float)DA_value)*0.1/(0.3*(float)AD_TimeSet);
 //  b=(u16) a;
  if((u32)a<=DA_value) 
  {
        //   DAC_SetChannel1Data(DAC_Align_12b_R,(u16)a); 
            DAC_SetChannel1Data_2((u16)a);
   // AD_now=b;
           ProgressShow();
         }
  else   //充电时间到.停止 DA++;
  {
           AD_count=0;  
    Tim2_DisableTIMBASE();      // 定时器2 禁止          //禁止定时器2中断。
           DA_Complete_Flag=TRUE;
           DA_Flag=FALSE;
          }
      }
    else
     if(n==2)  //做DA的设置参数修正
     {
      
     }
}   
void DeviceInit()//arm设备初始化
{
   DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
   SetupClock();                                               //建立系统时钟
   SetupGPIO();                                                //IO口初始化
   SetupUSART();                                               //串口初始化
   SetupDA();                                                //DA初始化
   SetupAD();                                                  //AD初始化
   DMA_Configuration_Temp();                                   //DMA初始化
   SetupAD_Temp();                                             //温度传感器初始化
   SysTick_Init();                                             //系统时钟初始化,用于精确定时1ms
   Tim2_SetupNVIC();                                           //定时器Tim2的中断使能.
   Tim2_DisableTIMBASE();                                    // 定时器2 禁止 
   Tim3_SetupNVIC();                                           //定时器Tim3的中断使能.
   Tim3_SetupTIMBASE();                                    // 定时器3 开启        
   I2C_GPIO_Config();                                          //EEPROM IO口线初始化
}
void ParaInit(void)//测量参数初始化
{
   total_HVnum=0;total_Timesnum=0;total_Intervalnum=0;total_Gradenum=0;total_Phasicnum=0;
   IntnumHV=0;IntnumTestTimes=1;IntnumTestInterval=0; IntnumTestGrade=0; IntnumTestphasic=0;
   Real_IntnumTestTimes=0;
   Bmp_ID=0;
   AD_count=0;//充电函数计数
   num=0xFF;
   Kcode=0xFF;
   Voltage=0;
   PolarityNum=0;//默认为先正
   PositiveNegative=0;//0 先正,1 先负,2 仅正.3 仅负.4 先正后负交替进行
   DA_Complete_Flag=FALSE;
   DA_Flag=FALSE;
   DoClear_Flag=FALSE;
   Run_All_Flag=FALSE;
   num_Flag=FALSE;
   Real_Set_Flag=FALSE;
   Real_NetIn_Flag=FALSE;
   Real_Earth_Flag=FALSE;
   THNum_Center_Flag=FALSE;
   THNum_Cancel_Flag=FALSE;        
   Main_Run_Flag=FALSE;
   Set_TestHV_Button_Flag=FALSE;
   Set_TestTimes_Button_Flag=FALSE;
   Set_TestInterval_Button_Flag=FALSE;
   Set_TestGrade_Button_Flag=FALSE;
   Set_TestAddPhasic_Button_Flag=FALSE ;
   Set_Center_Button_Flag=FALSE;
   Set_ADDNet_Button_Flag=FALSE;
   Set_OtherControl_Button_Flag=FALSE;
   OtherSet_SetPolarity_Botton_Falg=FALSE;
   OtherSet_Exit_Botton_Falg=FALSE;
   FirstRunBMP1=FALSE;
   i=0;                                                         //循环标志
   j=0; 
   DA(0);
}
void IOInit(void)

   GPIO_WriteBit(GPIOG,GPIO_Pin_15,(BitAction)(0));//使能所有的IO输出
   GPIO_WriteBit(GPIOA,GPIO_Pin_8,(BitAction)(0));
   GPIO_WriteBit(GPIOA,GPIO_Pin_9,(BitAction)(1)); //PA9关闭
   GPIO_WriteBit(GPIOA,GPIO_Pin_10,(BitAction)(1));//PA10关闭
   GPIO_WriteBit(GPIOB,GPIO_Pin_0,(BitAction)(1));
   GPIO_WriteBit(GPIOB,GPIO_Pin_1,(BitAction)(1));
   GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(1));//初始化PB5=1为闭合,充电电容处于放电状态
   GPIO_WriteBit(GPIOB,GPIO_Pin_6,(BitAction)(1));
   GPIO_WriteBit(GPIOB,GPIO_Pin_7,(BitAction)(1));
}

u16 NumDriver(int x,int y)  //数字显示驱动
{
  numSource[4]=num;
  for(i=0;i<4;i++)
  { numSource[i]=numSource[i+1];
    DisplayNum(x+i*16,y,numSource[i]);
  }
  return(numSource[0]*1000+numSource[1]*100+numSource[2]*10+numSource[3]);
 
}  
void Tim3_Delay_1ms(u32 nTime)  //系统时钟用于精确定时1ms
{
  // TIM IT enable  使能中断源
  TIM_ITConfig(TIM3,TIM_IT_Update, ENABLE);
  // TIM2 总开关,开启enable counter
  TIM_Cmd(TIM3, ENABLE);
  Tim3Delay = nTime; // 读取延时时间
  while(Tim3Delay != 0); // 判断延时是否结束
  // TIM IT enable  使能中断源
  TIM_ITConfig(TIM3,TIM_IT_Update, DISABLE);
  // TIM2 总开关,开启enable counter
  TIM_Cmd(TIM3, DISABLE);
}
void Systick_Delay_1ms(u32 nTime)  //系统时钟用于精确定时1ms
{
 SysTick_CounterCmd(SysTick_Counter_Enable); // 使能SysTick计数器
  TimingDelay = nTime; // 读取延时时间
  while(TimingDelay != 0); // 判断延时是否结束
  SysTick_CounterCmd(SysTick_Counter_Disable); // 关闭SysTick计数器
  SysTick_CounterCmd(SysTick_Counter_Clear); // 清除SysTick计数器
 
}
void DisplayZero(u8 n)
{

     THNum_Cancel_Flag=FALSE;
         for(i=0;i<4;i++)numSource[i]=0;
        switch(n)
        {
         case 111:    
           IntnumHV=0;
           for(i=0;i<4;i++)DisplayNum(DispTestHV_x+i*16,DispTestHV_y,0);break;
        case 112:
           IntnumTestTimes=0;
           for(i=0;i<4;i++)DisplayNum(DispTestTimes_x+i*16,DispTestTimes_y,0);break;
        case 113:
           IntnumTestInterval=0;
           for(i=0;i<4;i++)DisplayNum(DispTestInterval_x+i*16,DispTestInterval_y,0);break;
        case 114:
           IntnumTestGrade=0;
           for(i=0;i<4;i++)DisplayNum(DispTestGrade_x+i*16,DispTestGrade_y,0);break;
        case 115:
          IntnumTestphasic=0;
          for(i=0;i<4;i++)DisplayNum(DispTestphasic_x+i*16,DispTestphasic_y,0);break;
         
      default:break;
        }
}

 

void DisplayPhasicZero(void)
{
   for(i=0;i<4;i++)numSource[i]=0;
       
     THNum_Cancel_Flag=FALSE;
  
}
void Do_Process(void)           //主要控制流程  
{    
       //SaveToEEPROM();//保存试验极性
  switch(PositiveNegative)
  {
   case 0://先正               
                break;
   case 1://先负
                  break;
   case 2://仅正
                  GPIO_WriteBit(GPIOA,GPIO_Pin_10,(BitAction)(1)); //PA10关闭
     GPIO_WriteBit(GPIOA,GPIO_Pin_9,(BitAction)(0)); //打开PA9=0打开正极性
                  break;
   case 3://仅负
                  GPIO_WriteBit(GPIOA,GPIO_Pin_10,(BitAction)(0)); // PA10打开正极性
     GPIO_WriteBit(GPIOA,GPIO_Pin_9,(BitAction)(1)); //   PA9=1关闭
                  break;
   case 4://先正后负 交替
                  break;
   }   
   GPIO_WriteBit(GPIOB,GPIO_Pin_5,(BitAction)(0)); //打开PB5=0开关,充电电容可以充电   
   DA_Flag=TRUE;//DA充电    
          Run_All_Flag=FALSE;
}
void Printn(u16 x,u16 y,u16 n,u8 bmpID)  //四位数 数据变量的显示
{ u8 a;
  u8 b;
  u8 c;
  u8 d;
  switch( bmpID)
  {
case 3:
  SendChar(0xAA);SendChar(0x40);SendChar(0xF8);SendChar(0x00);SendChar(0xFF);SendChar(0xFF); TxEOF(); //设置当前调色板颜色.背景白色,前景红色
  SendChar(0xAA);
  SendChar(0x55);  //32*32 ASCII码
  TxWord(x);
  TxWord(y);
  a=n/1000;
  SendChar(0x30+a);
  b=(n-a*1000)/100;
  SendChar(0x30+b);
  c=(n-a*1000-b*100)/10;
  SendChar(c+0x30);
  d=n-a*1000-b*100-c*10;
  SendChar(0x30+d);
  TxEOF();
  break;
case 1:
  SendChar(0xAA);SendChar(0x40);SendChar(0xF8);SendChar(0x00);SendChar(0xC6);SendChar(0x18); TxEOF(); //设置当前调色板.背景灰色,前景红色
  SendChar(0xAA);
  SendChar(0x54);    //32*132ASCII码
  TxWord(x);
  TxWord(y);
  a=n/1000;
  SendChar(0x30+a);
  b=(n-a*1000)/100;
  SendChar(0x30+b);
  c=(n-a*1000-b*100)/10;
  SendChar(c+0x30);
  d=n-a*1000-b*100-c*10;
  SendChar(0x30+d);
  TxEOF();
  break;
default:break;
  }
}
void DisplayPolarityOnOtherSetBmp(u8 n) //显示极性文本变量
{
  SendChar(0xAA);SendChar(0x40);SendChar(0xF8);SendChar(0x00);SendChar(0xFF);SendChar(0xFF); TxEOF(); //设置当前调色板颜色.背景白色,前景红色
  SendChar(0xAA);
  SendChar(0x55);
  TxWord(OtherSetBmp_SetPolarity_X);
  TxWord(OtherSetBmp_SetPolarity_y);
   switch(n)
  {
  case 0:TxWord(0xCFC8);TxWord(0xD5FD);break;//先正
  case 1:TxWord(0xCFC8);TxWord(0xB8BA);break;//先负
  case 2:TxWord(0xBDF6);TxWord(0xD5FD);break;//仅正
  case 3:TxWord(0xBDF6);TxWord(0xB8BA);break;//仅负
  case 4:TxWord(0xBDBB);TxWord(0xCCE6);break;//先正后负 交替
  }
    TxEOF();
}
void ClearProgressScreen()//清滚动条小屏幕
{
  TxWord(0xAA40);  //设置调色板的颜色
  TxWord(0xFFFF);//前景色为白色
  TxWord(0x3186);//背景色为黑灰色
  TxEOF();
 
  TxWord(0xAA5A);//以背景色填充(对滚动条进行刷屏)
  TxWord(0x0008);//左上X
  TxWord(0x00F4);//左上Y
  TxWord(0x013B);//右下X
  TxWord(0x0104);//右下Y
  TxEOF();
}
void ProgressShow(void)
{
    j++;
    if(j%600 == 0)
    {
     if(Bmp_ID==1)
     {
      i+=1;
      DoProgressShow(i); 
      if(i>240) {i=0;ClearProgressScreen(); }
      }
     }
}
void DoProgressShow(int i)  //主画面进度条显示运行进程
{
  TxWord(0xAA71);
  SendChar(0x02);//滚动条存于第二幅图片中
  TxWord(0x0069);//左上X
  TxWord(0x00F4);//左上Y
  TxWord(0x00A7);//右下X
  TxWord(0x0103);//右下Y
 // for(i=0;i<304;i++)
  TxWord(0x0008+i);//显示X
  TxWord(0x00F4);//显示Y
  TxEOF();
}

void ClearScreen(u8 n)   //刷屏
{
  switch(n)
  {
  case 1:SendChar(0xAA);SendChar(0x70);SendChar(0x01);TxEOF();  break;//刷屏
  case 11:SendChar(0xAA);SendChar(0x70);SendChar(0x03);TxEOF(); break; //刷屏
  case 116:SendChar(0xAA);SendChar(0x70);SendChar(0x07);TxEOF();  break;//刷屏
  default :break;
  }
  DoClear_Flag=TRUE;
}
void DisplayOnBmp(u8 n)//显示
{
 switch(n)
 {
case 1:
   //在实测画面中显示实际运行得到的参数
  SendChar(0xAA);SendChar(0x54);TxWord(Real_DispRealHV_x-0x10);TxWord(Real_DispRealHV_y);
    if(PositiveNegative==2)//仅正
    SendChar(0x2B);//'+'
    else if(PositiveNegative==3)//仅负
    SendChar(0x2D);//'-'
    TxEOF(); 
    Printn(Real_DispRealHV_x,Real_DispRealHV_y,IntnumHV,1);
    Printn(Real_DispRealTimes_x,Real_DispRealTimes_y,Real_IntnumTestTimes,1);
    Printn(Real_DispRealInterval_x,Real_DispRealInterval_y,IntnumTestInterval,1);
    Printn(Real_DispRealGrade_x,Real_DispRealGrade_y,IntnumTestGrade,1);
    Printn(Real_DispRealphasic_x,Real_DispRealphasic_y,IntnumTestphasic,1);
   //在实测画面中显示上次的设置参数
    SendChar(0xAA);SendChar(0x54);TxWord(Real_DispTestHV_x-0x10);TxWord(Real_DispTestHV_y);
    if(PositiveNegative==2)//仅正
    SendChar(0x2B);//'+'
    else if(PositiveNegative==3)//仅负
    SendChar(0x2D);//'-'
    TxEOF(); 
    Printn(Real_DispTestHV_x,Real_DispTestHV_y,IntnumHV,1);
    Printn(Real_DispTestTimes_x,Real_DispTestTimes_y,IntnumTestTimes,1);
    Printn(Real_DispTestInterval_x,Real_DispTestInterval_y,IntnumTestInterval,1);
    Printn(Real_DispTestGrade_x,Real_DispTestGrade_y,IntnumTestGrade,1);
    Printn(Real_DispTestphasic_x,Real_DispTestphasic_y,IntnumTestphasic,1);
    break;
case 11:
  //在设置画面中显示上次的设置参数
    SendChar(0xAA);SendChar(0x55);TxWord(DispTestHV_x-0x10);TxWord(DispTestHV_y);
    if(PositiveNegative==2)//仅正
    SendChar(0x2B);//'+'
    else if(PositiveNegative==3)//仅负
    SendChar(0x2D);//'-'
    TxEOF(); 
    Printn(DispTestHV_x,DispTestHV_y,IntnumHV,3);
    Printn(DispTestTimes_x,DispTestTimes_y,IntnumTestTimes,3);
    Printn(DispTestInterval_x,DispTestInterval_y,IntnumTestInterval,3);
    Printn(DispTestGrade_x,DispTestGrade_y,IntnumTestGrade,3);
    Printn(DispTestphasic_x,DispTestphasic_y,IntnumTestphasic,3);
    break;
case 116: //在其它设置画面中显示极性
    switch(PositiveNegative)
           {
     case 0:DisplayPolarityOnOtherSetBmp(0);break;
     case 1:DisplayPolarityOnOtherSetBmp(1);break;
     case 2:DisplayPolarityOnOtherSetBmp(2);break;
     case 3:DisplayPolarityOnOtherSetBmp(3);break;
     case 4:DisplayPolarityOnOtherSetBmp(4);break;
                default:break;
           }
    break;
default :break;
 }
}
void TCH_Process()
{
   switch(Kcode)
     {      case 0x18:
                Bmp_ID=1;
                ReadfromEEProm();
                ClearScreen(1);//刷屏
                DisplayOnBmp(1);//显示
                FirstRunBMP1=TRUE;
                Kcode=0xFF;
                break;
             case 0x00:
             case 0x01:
             case 0x02:
             case 0x03:
             case 0x04: 
             case 0x05:
             case 0x06:
             case 0x07:
             case 0x08:
             case 0x09:
               num=Kcode;
               num_Flag=TRUE;
               Real_IntnumTestTimes=0;
               Kcode=0xFF;
               switch(Bmp_ID)
               {
               case 111: IntnumHV= NumDriver(DispTestHV_x,DispTestHV_y);                     break;
               case 112: IntnumTestTimes=NumDriver(DispTestTimes_x,DispTestTimes_y);         break;
               case 113: IntnumTestInterval=NumDriver(DispTestInterval_x,DispTestInterval_y);break;
               case 114: IntnumTestGrade=NumDriver(DispTestGrade_x,DispTestGrade_y);         break;
               case 115: IntnumTestphasic=NumDriver(DispTestphasic_x,DispTestphasic_y);      break;
               default:break;
               }
               break; 
             case 0x0A:
                Bmp_ID=11;
                THNum_Center_Flag =TRUE ;
                ClearScreen(11);//刷屏
                DisplayOnBmp(11);//显示
                SaveToEEPROM(); //保存所有设置的参数
                for(i=0;i<4;i++)numSource[i]=0;
                Kcode=0xFF;
                break; 
             case 0x0B:
               THNum_Cancel_Flag =TRUE ;
               DisplayZero(Bmp_ID);
               Kcode=0xFF;
               break;
             case 0x0C:
               Bmp_ID=11;
               Real_Set_Flag=TRUE;
               ReadfromEEProm();
               ClearScreen(11);//刷屏
               DisplayOnBmp(11);//显示
               Kcode=0xFF;
               break; 
             case 0x0D:
               Real_NetIn_Flag=TRUE;    Kcode=0xFF;break;  
             case 0x0E:
               All_Stop_Flag=TRUE;    Kcode=0xFF;break;  
             case 0x0F:
              if(IntnumTestTimes>0) Run_All_Flag=TRUE;  Real_IntnumTestTimes=0;DisplayOnBmp(1);  Kcode=0xFF;break;
             case 0x10:
               Set_TestHV_Button_Flag=TRUE;Bmp_ID=111; ReadfromEEProm(); DisplayOnBmp(11);//显示
               Kcode=0xFF;
               break;
             case 0x11:
               Set_TestTimes_Button_Flag=TRUE;Bmp_ID=112; ReadfromEEProm(); DisplayOnBmp(11);//显示
               Kcode=0xFF;
               break;
             case 0x12:
               Set_TestInterval_Button_Flag=TRUE;Bmp_ID=113;  ReadfromEEProm();DisplayOnBmp(11);//显示
                 Kcode=0xFF;
               break;
             case 0x13:
               Set_TestGrade_Button_Flag=TRUE; Bmp_ID=114; ReadfromEEProm(); DisplayOnBmp(11);//显示
               Kcode=0xFF;
               break;
             case 0x14:
               Set_TestAddPhasic_Button_Flag=TRUE; Bmp_ID=115; ReadfromEEProm(); DisplayOnBmp(11);//显示
               Kcode=0xFF;
               break;
             case 0x15:
                 Set_Center_Button_Flag=TRUE;
                 Bmp_ID=1;
                 ReadfromEEProm();
                 ClearScreen(1);//刷屏
                 DisplayOnBmp(1);//显示
                 Kcode=0xFF;
                 break;
             case 0x16:
               Set_ADDNet_Button_Flag=TRUE;
               break;
             case 0x17:
                Bmp_ID=116;
                Set_OtherControl_Button_Flag=TRUE;
                ReadfromEEProm();
                ClearScreen(116);//刷屏
                DisplayOnBmp(116);//显示
                Kcode=0xFF;
                break;
             case 0x19:
               OtherSet_SetPolarity_Botton_Falg=TRUE;
           switch(PolarityNum)
           {
                case 0:DisplayPolarityOnOtherSetBmp(PolarityNum);PositiveNegative=0;break;
                case 1:DisplayPolarityOnOtherSetBmp(PolarityNum);PositiveNegative=1;break;
     case 2:DisplayPolarityOnOtherSetBmp(PolarityNum);PositiveNegative=2;break;
     case 3:DisplayPolarityOnOtherSetBmp(PolarityNum);PositiveNegative=3;break;
     case 4:DisplayPolarityOnOtherSetBmp(PolarityNum);PolarityNum=0;PositiveNegative=4;break;
                default:break;
           }
               SaveToEEPROM();//保存试验极性
           PolarityNum++;
               Kcode=0xFF;
               break;
             case 0x1A:
               Bmp_ID=11;
               OtherSet_Exit_Botton_Falg=TRUE;
                ReadfromEEProm();
                ClearScreen(11);//刷屏
                DisplayOnBmp(11);//显示
                Kcode=0xFF;
                break;      
             default:  break;
      }
 
    TCHOK=TRUE;
}
void SaveToEEPROM()  //将所有数据保存到EEPROM
{
         IntnumHV_H          =  IntnumHV/256 ;     
         IntnumHV_L          =  IntnumHV%256 ;
         Real_IntnumHV_H     =  Real_IntnumHV/256 ;     
         Real_IntnumHV_L     =  Real_IntnumHV%256 ;   
         IntnumTestTimes_H   =  IntnumTestTimes/256 ;     
         IntnumTestTimes_L   =  IntnumTestTimes%256 ;    
         IntnumTestInterval_H=  IntnumTestInterval/256 ;     
         IntnumTestInterval_L=  IntnumTestInterval%256 ;
         IntnumTestGrade_H   =  IntnumTestGrade/256 ;     
         IntnumTestGrade_L   =  IntnumTestGrade%256 ;
         IntnumTestphasic_H  =  IntnumTestphasic/256 ;     
         IntnumTestphasic_L  =  IntnumTestphasic%256 ;
         PositiveNegative_H  =  PositiveNegative/256 ;     
         PositiveNegative_L  =  PositiveNegative%256 ;
        
         Tx1_Buffer[0]  =  Real_IntnumHV_H           ;  //实际已冲击的次数         backup0 
  Tx1_Buffer[1]  =  IntnumTestTimes_H            ;  //试验次数                 backup1
  Tx1_Buffer[2]  =  IntnumTestInterval_H            ;  //试验间隔,  单位 s      backup2
  Tx1_Buffer[3]  =  IntnumHV_H        ;  //冲击电压     backup3
  Tx1_Buffer[4]  =  IntnumTestGrade_H          ;  //试验等级,0-4;0为X级  backup4
  Tx1_Buffer[5]  =  IntnumTestphasic_H              ;  //相位 0-359    backup5      backup3
 /* int_char.K_int[6]  =  U_phasic            ;  //相位基准L1,L2,L3,0--2  backup6
  int_char.K_int[7]  =  add_mode            ;  //迭加方式 0:同步,1:异步 backup7*/
  Tx1_Buffer[8]  =  PositiveNegative_H            ;  //试验极性 0-4;0:仅正,1:仅负,2:先正,3:先负 4:交替 backup8
 /* int_char.K_int[9]  =  test_mode           ;  //试验方式 0-1;0:连续,1:单次         backup9
  int_char.K_int[10] =  trigger_mode        ;  //触发方式 0-1;0:自动,1:手动        backup10
  int_char.K_int[11] =  measure_enble       ;  //峰值测量 0-3; 0:切除,1:仅电压,2仅电流,3全投入;??backup11
  int_char.K_int[12] =  safeguard           ;  //击穿保护 0-1;0:切除,1:投入        backup12
  int_char.K_int[13] =  Upp_on              ;  //电压依据投入 ;0:切除,1:投入        backup13
  int_char.K_int[14] =  Ipp_on              ;  //电流依据投入 ;0:切除,1:投入        backup14
  int_char.K_int[15] =  Upp_n               ;  //电压依据     backup15
  int_char.K_int[16] =  Ipp_n               ;  //电流依据     backup16
  int_char.K_int[17] =  phasic_coefficient  ;  //相位修正 us     backup17
  int_char.K_int[18] =  potentiometer_ratio ;  //分压比  ×10    backup18
  int_char.K_int[19] =  shunt_resistance    ;  //分流器电阻 ×1000  backup19
  int_char.K_int[20] =  dummy_resistance    ;  //虚拟电阻 ×1000    backup20
  int_char.K_int[21] =  efficiency          ;  //效率%,×100    backup21
  int_char.K_int[22] =  a1                  ;  //峰值电压 ×1000    backup22
  int_char.K_int[23] =  b1                  ;  //峰值电压偏置    backup23
  int_char.K_int[24] =  b1_polarity         ;  //0:正; 1:负      backup24
  int_char.K_int[25] =  a2                  ;  //峰值电压 ×1000    backup25
  int_char.K_int[26] =  b2                  ;  //峰值电压偏置    backup26
  int_char.K_int[27] =  b2_polarity         ;  //0:正; 1:负      backup27
  int_char.K_int[28] =  a3                  ;  //峰值电流 ×1000    backup28
  int_char.K_int[29] =  b3                  ;  //峰值电流偏置    backup29
  int_char.K_int[30] =  b3_polarity         ;  //0:正; 1:负      backup30
  int_char.K_int[31] =  a4                  ;  //峰值电流 ×1000    backup31
  int_char.K_int[32] =  b4                  ;  //峰值电流偏置    backup32
  int_char.K_int[33] =  b4_polarity         ;  //0:正; 1:负      backup33
  int_char.K_int[34] =  electricize_time    ;  //充电时间,0-199    backup34
  int_char.K_int[35] =  state_data_byte     ;  //状态字备份        backup35
  int_char.K_int[36] =  net_adding          ;  //连接网络           backup36 0:无网络;1:单相;2:三相
  int_char.K_int[37] =  Kgd                 ;  //给定系数 ×1000    backup37
  int_char.K_int[38] =  GD_zero             ;  //给定偏置           backup38
  int_char.K_int[39] =  GD_zero_polarity    ;  //0:正; 1:负      backup39        
  int_char.K_int[40] =  Ku                  ;  //高压测量系数×1000 backup40
  int_char.K_int[41] =  Ku_zero             ;  //给定偏置        backup41 
  int_char.K_int[42] =  Ku_zero_polarity    ;  //0:正; 1:负      backup42 
  int_char.K_int[43] =  K_cg                ;   //                 backup43
  int_char.K_int[44] =  R_out               ;   //                 backup44
  net_data_w();*/
        
         Tx1_Buffer[45]  =  Real_IntnumHV_L           ;  //实际已冲击的次数         backup0 
  Tx1_Buffer[46]  =  IntnumTestTimes_L            ;  //试验次数                 backup1
  Tx1_Buffer[47]  =  IntnumTestInterval_L            ;  //试验间隔,  单位 s      backup2
  Tx1_Buffer[48]  =  IntnumHV_L        ;  //冲击电压     backup3
  Tx1_Buffer[49]  =  IntnumTestGrade_L          ;  //试验等级,0-4;0为X级  backup4
  Tx1_Buffer[50]  =  IntnumTestphasic_L              ;  //相位 0-359    backup5      backup3
 /* int_char.K_int[6]  =  U_phasic            ;  //相位基准L1,L2,L3,0--2  backup6
  int_char.K_int[7]  =  add_mode            ;  //迭加方式 0:同步,1:异步 backup7*/
  Tx1_Buffer[53]  =  PositiveNegative_L            ;  //试验极性 0-4;0:仅正,1:仅负,2:先正,3:先负 4:交替 backup8
 /* int_char.K_int[9]  =  test_mode           ;  //试验方式 0-1;0:连续,1:单次         backup9
  int_char.K_int[10] =  trigger_mode        ;  //触发方式 0-1;0:自动,1:手动        backup10
  int_char.K_int[11] =  measure_enble       ;  //峰值测量 0-3; 0:切除,1:仅电压,2仅电流,3全投入;??backup11
  int_char.K_int[12] =  safeguard           ;  //击穿保护 0-1;0:切除,1:投入        backup12
  int_char.K_int[13] =  Upp_on              ;  //电压依据投入 ;0:切除,1:投入        backup13
  int_char.K_int[14] =  Ipp_on              ;  //电流依据投入 ;0:切除,1:投入        backup14
  int_char.K_int[15] =  Upp_n               ;  //电压依据     backup15
  int_char.K_int[16] =  Ipp_n               ;  //电流依据     backup16
  int_char.K_int[17] =  phasic_coefficient  ;  //相位修正 us     backup17
  int_char.K_int[18] =  potentiometer_ratio ;  //分压比  ×10    backup18
  int_char.K_int[19] =  shunt_resistance    ;  //分流器电阻 ×1000  backup19
  int_char.K_int[20] =  dummy_resistance    ;  //虚拟电阻 ×1000    backup20
  int_char.K_int[21] =  efficiency          ;  //效率%,×100    backup21
  int_char.K_int[22] =  a1                  ;  //峰值电压 ×1000    backup22
  int_char.K_int[23] =  b1                  ;  //峰值电压偏置    backup23
  int_char.K_int[24] =  b1_polarity         ;  //0:正; 1:负      backup24
  int_char.K_int[25] =  a2                  ;  //峰值电压 ×1000    backup25
  int_char.K_int[26] =  b2                  ;  //峰值电压偏置    backup26
  int_char.K_int[27] =  b2_polarity         ;  //0:正; 1:负      backup27
  int_char.K_int[28] =  a3                  ;  //峰值电流 ×1000    backup28
  int_char.K_int[29] =  b3                  ;  //峰值电流偏置    backup29
  int_char.K_int[30] =  b3_polarity         ;  //0:正; 1:负      backup30
  int_char.K_int[31] =  a4                  ;  //峰值电流 ×1000    backup31
  int_char.K_int[32] =  b4                  ;  //峰值电流偏置    backup32
  int_char.K_int[33] =  b4_polarity         ;  //0:正; 1:负      backup33
  int_char.K_int[34] =  electricize_time    ;  //充电时间,0-199    backup34
  int_char.K_int[35] =  state_data_byte     ;  //状态字备份        backup35
  int_char.K_int[36] =  net_adding          ;  //连接网络           backup36 0:无网络;1:单相;2:三相
  int_char.K_int[37] =  Kgd                 ;  //给定系数 ×1000    backup37
  int_char.K_int[38] =  GD_zero             ;  //给定偏置           backup38
  int_char.K_int[39] =  GD_zero_polarity    ;  //0:正; 1:负      backup39        
  int_char.K_int[40] =  Ku                  ;  //高压测量系数×1000 backup40
  int_char.K_int[41] =  Ku_zero             ;  //给定偏置        backup41 
  int_char.K_int[42] =  Ku_zero_polarity    ;  //0:正; 1:负      backup42 
  int_char.K_int[43] =  K_cg                ;   //                 backup43
  int_char.K_int[44] =  R_out               ;   //                 backup44
  net_data_w();*/
        
         for(i=0;i<90;i++)               //0000开始
  {
             I2C_BufferWrite(Tx1_Buffer,BufferSize1,EEPROM_WriteAddress1,0xa0);
  }
 
}
void ReadfromEEProm()//将所有数据从EEPROM中读出来
{
   unsigned char i;

  for(i=0;i<90;i++)          //0000开始
  {//Rx1_Buffer[i]=
     I2C_ReadByte(Rx1_Buffer,BufferSize1,0x00 ,0xa0);;
  }
  Real_IntnumHV_H      = Rx1_Buffer[0];  //实际已冲的击次数         backup0 
  IntnumTestTimes_H    = Rx1_Buffer[1];  //试验次数                 backup1
  IntnumTestInterval_H = Rx1_Buffer[2];  //试验间隔,  单位 s      backup2
  IntnumHV_H           = Rx1_Buffer[3];  //冲击电压     backup3
  IntnumTestGrade_H    = Rx1_Buffer[4];  //试验等级,0-4;0为X级  backup4
  IntnumTestphasic_H   = Rx1_Buffer[5];  //相位 0-359    backup5
/*  U_phasic           = int_char.K_int[6];  //相位基准L1,L2,L3,0--2  backup6
  add_mode           = int_char.K_int[7];  //迭加方式 0:同步,1:异步 backup7*/
  PositiveNegative_H   = Rx1_Buffer[8];  //试验极性 0-4;0:仅正,1:仅负,2:先正,3:先负 4:交替 backup8
 /* test_mode          = int_char.K_int[9];  //试验方式 0-1;0:连续,1:单次         backup9
  trigger_mode       = int_char.K_int[10]; //触发方式 0-1;0:自动,1:手动        backup10
  measure_enble      = int_char.K_int[11]; //峰值测量 0-3; 0:切除,1:仅电压,2仅电流,3全投入;??backup11
  safeguard          = int_char.K_int[12]; //击穿保护 0-1;0:切除,1:投入        backup12
  Upp_on             = int_char.K_int[13]; //电压依据投入 ;0:切除,1:投入        backup13
  Ipp_on             = int_char.K_int[14]; //电流依据投入 ;0:切除,1:投入        backup14
  Upp_n              = int_char.K_int[15]; //电压依据     backup15
  Ipp_n              = int_char.K_int[16]; //电流依据     backup16
  phasic_coefficient = int_char.K_int[17]; //相位修正 us     backup17
  potentiometer_ratio= int_char.K_int[18]; //分压比  ×10    backup18
  shunt_resistance   = int_char.K_int[19]; //分流器电阻 ×1000  backup19
  dummy_resistance   = int_char.K_int[20]; //虚拟电阻 ×1000    backup20
  efficiency         = int_char.K_int[21]; //效率%,×100    backup21
  a1                 = int_char.K_int[22]; //峰值电压 ×1000    backup22
  b1                 = int_char.K_int[23]; //峰值电压偏置    backup23
  b1_polarity        = int_char.K_int[24]; //0:正; 1:负      backup24
  a2                 = int_char.K_int[25]; //峰值电压 ×1000    backup25
  b2                 = int_char.K_int[26]; //峰值电压偏置    backup26
  b2_polarity        = int_char.K_int[27]; //0:正; 1:负      backup27
  a3                 = int_char.K_int[28]; //峰值电流 ×1000    backup28
  b3                 = int_char.K_int[29]; //峰值电流偏置    backup29
  b3_polarity        = int_char.K_int[30]; //0:正; 1:负      backup30
  a4                 = int_char.K_int[31]; //峰值电流 ×1000    backup31
  b4                 = int_char.K_int[32]; //峰值电流偏置    backup32
  b4_polarity        = int_char.K_int[33]; //0:正; 1:负      backup33
  electricize_time   = int_char.K_int[34]; //充电时间,0-199    backup34
  state_data_byte    = int_char.K_int[35]; //状态字备份        backup35
  net_adding   = int_char.K_int[36]; //连接网络           backup36 0:无网络;1:单相;2:三相
     Kgd          = int_char.K_int[37]; //给定系数 ×1000    backup37
  GD_zero   = int_char.K_int[38]; //给定偏置           backup38
  GD_zero_polarity = int_char.K_int[39]; //0:正; 1:负      backup39        
  Ku          = int_char.K_int[40]; //高压测量系数×1000 backup40
  Ku_zero   = int_char.K_int[41]; //给定偏置        backup41 
  Ku_zero_polarity = int_char.K_int[42]; //0:正; 1:负      backup42 
  K_cg    = int_char.K_int[43]; //                 backup43 
  R_out    = int_char.K_int[44]; //                 backup44 
 

  if(Ku==0)          Ku = 1000;     //初次起机
  if(efficiency==0) efficiency = 10000; 

  net_data_r();
  net_state();
  net_know();

  test_voltage_now_view=test_voltage_now;
  test_grade_now_view  =test_grade_now; */


/*                    //首次运行必须运行之
  Kgd          = 1000;     //给定系数 ×1000    backup37
  GD_zero   = 0;        //给定偏置           backup38
  GD_zero_polarity = 0;        //0:正; 1:负      backup39        
  Ku          = 1000;     //高压测量系数×1000 backup40
  Ku_zero   = 0;        //给定偏置        backup41 
  Ku_zero_polarity = 0;        //0:正; 1:负      backup42 */
        
          Real_IntnumHV_L      = Rx1_Buffer[45];  //实际已冲的击次数         backup0 
  IntnumTestTimes_L    = Rx1_Buffer[46];  //试验次数                 backup1
  IntnumTestInterval_L = Rx1_Buffer[47];  //试验间隔,  单位 s      backup2
  IntnumHV_L           = Rx1_Buffer[48];  //冲击电压     backup3
  IntnumTestGrade_L    = Rx1_Buffer[49];  //试验等级,0-4;0为X级  backup4
  IntnumTestphasic_L   = Rx1_Buffer[50];  //相位 0-359    backup5
/*  U_phasic           = int_char.K_int[6];  //相位基准L1,L2,L3,0--2  backup6
  add_mode           = int_char.K_int[7];  //迭加方式 0:同步,1:异步 backup7*/
  PositiveNegative_L   = Rx1_Buffer[53];  //试验极性 0-4;0:仅正,1:仅负,2:先正,3:先负 4:交替 backup8
 /* test_mode          = int_char.K_int[9];  //试验方式 0-1;0:连续,1:单次         backup9
  trigger_mode       = int_char.K_int[10]; //触发方式 0-1;0:自动,1:手动        backup10
  measure_enble      = int_char.K_int[11]; //峰值测量 0-3; 0:切除,1:仅电压,2仅电流,3全投入;??backup11
  safeguard          = int_char.K_int[12]; //击穿保护 0-1;0:切除,1:投入        backup12
  Upp_on             = int_char.K_int[13]; //电压依据投入 ;0:切除,1:投入        backup13
  Ipp_on             = int_char.K_int[14]; //电流依据投入 ;0:切除,1:投入        backup14
  Upp_n              = int_char.K_int[15]; //电压依据     backup15
  Ipp_n              = int_char.K_int[16]; //电流依据     backup16
  phasic_coefficient = int_char.K_int[17]; //相位修正 us     backup17
  potentiometer_ratio= int_char.K_int[18]; //分压比  ×10    backup18
  shunt_resistance   = int_char.K_int[19]; //分流器电阻 ×1000  backup19
  dummy_resistance   = int_char.K_int[20]; //虚拟电阻 ×1000    backup20
  efficiency         = int_char.K_int[21]; //效率%,×100    backup21
  a1                 = int_char.K_int[22]; //峰值电压 ×1000    backup22
  b1                 = int_char.K_int[23]; //峰值电压偏置    backup23
  b1_polarity        = int_char.K_int[24]; //0:正; 1:负      backup24
  a2                 = int_char.K_int[25]; //峰值电压 ×1000    backup25
  b2                 = int_char.K_int[26]; //峰值电压偏置    backup26
  b2_polarity        = int_char.K_int[27]; //0:正; 1:负      backup27
  a3                 = int_char.K_int[28]; //峰值电流 ×1000    backup28
  b3                 = int_char.K_int[29]; //峰值电流偏置    backup29
  b3_polarity        = int_char.K_int[30]; //0:正; 1:负      backup30
  a4                 = int_char.K_int[31]; //峰值电流 ×1000    backup31
  b4                 = int_char.K_int[32]; //峰值电流偏置    backup32
  b4_polarity        = int_char.K_int[33]; //0:正; 1:负      backup33
  electricize_time   = int_char.K_int[34]; //充电时间,0-199    backup34
  state_data_byte    = int_char.K_int[35]; //状态字备份        backup35
  net_adding   = int_char.K_int[36]; //连接网络           backup36 0:无网络;1:单相;2:三相
     Kgd          = int_char.K_int[37]; //给定系数 ×1000    backup37
  GD_zero   = int_char.K_int[38]; //给定偏置           backup38
  GD_zero_polarity = int_char.K_int[39]; //0:正; 1:负      backup39        
  Ku          = int_char.K_int[40]; //高压测量系数×1000 backup40
  Ku_zero   = int_char.K_int[41]; //给定偏置        backup41 
  Ku_zero_polarity = int_char.K_int[42]; //0:正; 1:负      backup42 
  K_cg    = int_char.K_int[43]; //                 backup43 
  R_out    = int_char.K_int[44]; //                 backup44 */
 

         IntnumHV = IntnumHV_H*256+IntnumHV_L;    
         Real_IntnumHV = Real_IntnumHV_H*256+Real_IntnumHV_L;
    
         IntnumTestTimes = IntnumTestTimes_H*256+IntnumTestTimes_L;        
         IntnumTestInterval = IntnumTestInterval_H*256+IntnumTestInterval_L;
         IntnumTestGrade = IntnumTestGrade_H*256+IntnumTestGrade_L;
         IntnumTestphasic = IntnumTestphasic_H*256+IntnumTestphasic_L;      
         PositiveNegative = PositiveNegative_H*256+PositiveNegative_L;
}
void protect()
{
  if(IntnumHV <= 0)           MessageBox(0);
  if(IntnumTestTimes <= 0)    MessageBox(1);
  if(IntnumTestTimes <= 0)    MessageBox(2);
  if(IntnumTestInterval <= 0) MessageBox(3);
  All_Stop_Flag=TRUE;
}
void MessageBox(int n)
{
  switch(n)
  {
  case 0:break;
  case 1:break;
  case 2:break;
  case 3:break;
  }
}

你可能感兴趣的:(buffer,button,delay,float,网络,byte)