//-------------------------------------------------------------------------------
void kpa_display(void) //采集压力和设定压力显示程序
{
switch(xlhao)
{
case 0: //采集压力显示
{
if(kpa_hz_biao) //判断是否显示设定压力值
{
if(ssw_biao1==0)
{
P2OUT=0x01; //设置压力显示
P1OUT=sdata[scout4]; //只显示设定压力值,不显示频率
xlhao=1;
break;
}
else
xlhao=1;
}
else
xlhao=1;
}
case 1:
{
if(ssw_biao2==0)
{
P2OUT=0x02;
if(kpa_hz_biao)
P1OUT=sdata[scout3];
else
P1OUT=sdata[hcout3];
xlhao=2;
break;
}
else
xlhao=2;
}
case 2:
{
if(ssw_biao3==0)
{
P2OUT=0x04;
if(kpa_hz_biao)
P1OUT=sdata[scout2]&0xfe; //加上小数点
else
P1OUT=sdata[hcout2]&0xfe;
xlhao=3;
break;
}
else
xlhao=3;
}
case 3:
{
if(ssw_biao4==0)
{
P2OUT=0x08;
if(kpa_hz_biao)
P1OUT=sdata[scout1];
else
P1OUT=sdata[hcout1];
xlhao=4;
break;
}
else
xlhao=4; //如果不显示此位,则绕过
}
case 4: //设置压力显示
{
P2OUT=0x10;
P1OUT=sdata[ccout4];
xlhao=5;
break;
}
case 5:
{
P2OUT=0x20;
P1OUT=sdata[ccout3];
xlhao=6;
break;
}
case 6:
{
P2OUT=0x40;
P1OUT=sdata[ccout2]&0xfe; //加上小数点
xlhao=7;
break;
}
case 7:
{
P2OUT=0x80;
P1OUT=sdata[ccout1];
xlhao=0;
break;
}
}
}
//-------------------------------------------------------------------------------
void smg_tiqv(void) //数码管显示的值,提取程序
{
unsigned int ee=0;
ee=xian_kpa; //显示压力提取程序
ccout1=ee%10;
ee=ee/10;
ccout2=ee%10;
ee=ee/10;
ccout3=ee%10;
ee=ee/10;
ccout4=ee%10;
ee=xian_hz; //显示HZ提取程序
hcout1=ee%10;
ee=ee/10;
hcout2=ee%10;
ee=ee/10;
hcout3=ee%10;
ee=ee/10;
hcout4=ee%10;
}
//-------------------------------------------------------------------------------
void key_jiance(void)//按键检测程序
{
if(key5) key5_biao=0;
if((key5==0)&&(key5_biao==0)) //设置
{
key5_biao=1;
ssw_cout=0;
ssw_biao1=1;
kpa_hz_biao=1;//转换到设置压力显示
jiemian=1; //界面1
}
if(key3) key3_biao=0;
if((key3==0)&&(key3_biao==0)) //确定
{
key3_biao=1;
jiemian=0;
ssw_biao1=0;
ssw_biao2=0;
ssw_biao3=0;
ssw_biao4=0; //标志位清零
kpa_hz_biao=0; //转换到频率显示
skpa_cun(); //存储设定的压力值
}
if(key4) key4_biao=0;
if((key4==0)&&(key4_biao==0)) //位移
{
key4_biao=1;
ssw_cout++;
if(ssw_cout>3)
ssw_cout=0;
}
if(key1) key1_biao=0;
if((key1==0)&&(key1_biao==0)) //+
{
key1_biao=1;
skpa_tizh(1); //设置的压力值,调整函数
}
if(key2) key2_biao=0;
if((key2==0)&&(key2_biao==0)) //-
{
key2_biao=1;
skpa_tizh(0);
}
}
//-------------------------------------------------------------------------------
void skpa_tizh(unsigned char kbiao)//设定值位值计算程序
{
if(jiemian)
{
switch(ssw_cout)
{
case 0:
{
if(kbiao)
{
scout4++;
if(scout4>9) scout4=0;
}
else
{
if(scout4==0) scout4=10;
scout4--;
}
break;
}
case 1:
{
if(kbiao)
{
scout3++;
if(scout3>9) scout3=0;
}
else
{
if(scout3==0) scout3=10;
scout3--;
}
break;
}
case 2:
{
if(kbiao)
{
scout2++;
if(scout2>9) scout2=0;
}
else
{
if(scout2==0) scout2=10;
scout2--;
}
break;
}
case 3:
{
if(kbiao)
{
scout1++;
if(scout1>9) scout1=0;
}
else
{
if(scout1==0) scout1=10;
scout1--;
}
break;
}
default :break;
}
}
}
//-------------------------------------------------------------------------------
void skpa_cun(void) //把设定的压力值,进行计算并存储
{
unsigned int aa=0,bb=0,cc=0;
aa=scout4;
aa*=1000;
bb=scout3;
bb*=100;
cc=scout2;
cc*=10;
she_kpa=aa+bb+cc+scout1; //整理设置的压力值
she_bi_kpa=she_kpa; //设定值付给比较值
she_bi_kpa*=100; //计算设定值,比较数据值
addr_flash_write(); //把设置的压力值存到FLASH中
}
//-------------------------------------------------------------------------------
评论0