📄 ceshi.c.bak
字号:
constant_mtr[0]=constant_all[constant_cn*5];
constant_mtr[1]=constant_all[constant_cn*5+1];
constant_mtr[2]=constant_all[constant_cn*5+2];
constant_mtr[3]=constant_all[constant_cn*5+3];
}
}
if(an_start_cn >= 2 )
{
key_time=200;
//flashing=0;
have_pulse_cn=0;
if(an_start_flag!='D')
{ an_start_flag='D';
check_step=0x00;
flash_stop='F'; //消除在设置常数时闪烁位为隐藏状态。
save_cs(); //保存常数
read_cs(); //
}
}
if(an_stop_cn >= 2 )
{
key_time=200;
flashing=0;
have_pulse_cn=0;
an_start_flag=0;
check_step=0x00;
relay=1;
}
}
/**************************************************************************************
*
* FUNCTION: wc_over
*
* DESCRIPTION: 误差溢出数码管显示'E'.
*
* PARAMETERS: none
*
* RETURNED: none
*
*************************************************************************************/
void wc_over(void) //
{
led_show_list[0]=0x79;
if(sign_flag=='-')
{led_show_list[1]=0x40;}
else
{led_show_list[1]=0x00;}
led_show_list[2]=0x00;
led_show_list[3]=0x00;
led_show_list[4]=0x00;
led_show_list[5]=0x00;
led_show_flag='S';
}
/**************************************************************************************
*
* FUNCTION: wc_show
*
* DESCRIPTION: 以BCD码方式显示误差值.
*
* PARAMETERS: none
*
* RETURNED: none
*
*************************************************************************************/
void wc_show(uint m,uint n) //
{
uint i,j;
for(i=0;i<4;i++)
{ m*=10;
j=m/n;
led_show_list[3-i]= encoder[j];
m%=n;
}
led_show_list[2]+=0x80; //显示小数点.
if(sign_flag=='-')
{
if(led_show_list[3]==0x3f) //消除小数点前面的一个0
{
led_show_list[3]=0x40; //显示'-'号
led_show_list[4]=0x00;
}
else
{
led_show_list[4]=0x40; //显示'-'号
}
}
else
{
led_show_list[4]=0x00;
}
led_show_list[5]=0x00;
led_show_flag='S';
}
/**************************************************************************************
*
* FUNCTION: machine_electron
*
* DESCRIPTION: 检查是机械表还是电子表
*
* PARAMETERS: none
*
* RETURNED: none
*
*************************************************************************************/
void machine_electron()
{
if( constant_mtr[3]==6)
if( constant_mtr[2]==4)
if( constant_mtr[1]==0)
if( constant_mtr[0]==0)
{current_type='D'; return;}
if( constant_mtr[3]==3)
if( constant_mtr[2]==2)
if( constant_mtr[1]==0)
if( constant_mtr[0]==0)
{current_type='D'; return;}
if( constant_mtr[3]==1)
if( constant_mtr[2]==6)
if( constant_mtr[1]==0)
if( constant_mtr[0]==0)
{current_type='D'; return;}
if( constant_mtr[3]==0)
if( constant_mtr[2]==8)
if( constant_mtr[1]==0)
if( constant_mtr[0]==0)
{current_type='D'; return;}
current_type='J';
}
/**************************************************************************************
*
* FUNCTION: do_check
*
* DESCRIPTION: 处理检表开始
*
* PARAMETERS: none
*
* RETURNED: none
*
*************************************************************************************/
void do_check(void)
{ uint i,j;
unsigned long my_m,my_n,my_p;
if(an_start_flag=='D')
{
if(check_step==0)
{
flashing=0;
check_step=1;
relay=0; //闭合继电器
pulse_bz_cn=0x00;
pulse_dc_cn=0x00;
pulse_bz_time=0x00;
pulse_dc_time=0x00;
pulse_bz_t=0x00;
pulse_dc_t=0x00;
pulse_bz_flag=0x00;
pulse_dc_flag=0x00;
check_pulse='C'; //可以判断有无脉冲
check_time=CHECK_TIME; //
error=0; //出错
machine_electron(); //检查是机械表还是电子表
}
else if(check_step==1)
{
if(check_pulse=='F')
{
check_pulse=0x00;
pulse_bz_cn--;
my_m=pulse_bz_time;
my_m*=100; //标准表脉冲时间间隔的100倍
my_m/=pulse_bz_cn;
pulse_dc_cn--;
my_n=pulse_dc_time;
my_n*=100;
my_n/=pulse_dc_cn;
//单个字符的脉冲常数转换为整数。
my_p=1000*constant_mtr[3]+100*constant_mtr[2]+10*constant_mtr[1]+constant_mtr[0];
my_p*=100;
my_n=((my_p/64)*my_n)/10000; //应该为my_n=my_p*my_n/6400,考虑精度如此。 往标准表脉冲间隔转换。
if(my_n<=my_m)
{
sign_flag='+';
i=(my_m-my_n)%0xffff;
}
else
{
sign_flag='-';
i=(my_n-my_m)%0xffff;
}
j=my_m%0xffff;
if(i>=j)
{wc_over(); //误差过大,数码管显示'E'
}
else
{ wc_show(i,j); //显示误差
}
an_start_flag='D'; //继续检测
check_step=0x00;
showing=0; //当前显示的不是常数.
}
if(have_pulse) //
{
have_pulse=0;
beep_time=5;
/* have_pulse_cn++; //在第五号数码管上转圈显示,表示接收到待测表的脉冲。
if(have_pulse_cn > 6)
{have_pulse_cn=0;}
EXT_ADR=0x15;
switch(have_pulse_cn)
{
case 0:
EXT_DAT=0x01;break;
case 1:
EXT_DAT=0x02;break;
case 2:
EXT_DAT=0x04;break;
case 3:
EXT_DAT=0x08;break;
case 4:
EXT_DAT=0x10;break;
case 5:
EXT_DAT=0x20;break;
default:
break;
} */
}
if(beep_time!=0)
{beep=1;}
else
{beep=0;}
if(check_time ==0) //5秒之内脉冲太少
{
error='E';
an_start_flag='D'; //继续检测
check_step=0x00;
}
}
}
}
void do_error(void)
{
if(error=='E')
{
error=0;
led_show_list[0]=0x40;
led_show_list[1]=0x40;
led_show_list[2]=0x00;
led_show_list[3]=0x40;
led_show_list[4]=0x40;
led_show_list[5]=0x00;
led_show_flag='S';
}
}
/**************************************************************************************
*
* FUNCTION: do_flash
*
* DESCRIPTION: 检测状态时数码管显示特殊符号
*
* PARAMETERS: none
*
* RETURNED: none
*
*************************************************************************************/
/*
void do_flash(void)
{
uchar i;
if((flash_flag=='F')&(flash_ok=='F'))
{ //flash_flag=0;
flash_ok=0;
flash_cn++;
if(flash_cn>=6)
{flash_cn=0;}
if(flash_cn ==0)
{i=0x01;}
if(flash_cn==1)
{i=0x02;}
if(flash_cn==2)
{i=0x04;}
if(flash_cn==3)
{i=0x08;}
if(flash_cn==4)
{i=0x10;}
if(flash_cn==5)
{i=0x20;}
led_show_list[5]=i;
led_show_flag='S';
}
}*/
void show_data(void)
{
EXT_ADR=0x10;
EXT_DAT=led_show_list[0];
EXT_ADR=0x11;
EXT_DAT=led_show_list[1];
EXT_ADR=0x12;
EXT_DAT=led_show_list[2];
EXT_ADR=0x13;
EXT_DAT=led_show_list[3];
EXT_ADR=0x14;
EXT_DAT=led_show_list[4];
EXT_ADR=0x15;
EXT_DAT=led_show_list[5];
}
/**************************************************************************************
*
* FUNCTION: led_display
*
* DESCRIPTION: 数码管显示处理
*
* PARAMETERS: none
*
* RETURNED: none
*
*************************************************************************************/
void led_display(void)
{
if(flash_stop=='F')
{
flash_stop=0;
led_show_list[0]= encoder[constant_mtr[0]];
led_show_list[1]= encoder[constant_mtr[1]];
led_show_list[2]= encoder[constant_mtr[2]];
led_show_list[3]= encoder[constant_mtr[3]];
led_show_list[4]= 0;
led_show_list[5]= encoder[constant_cn];
show_data();
}
if(flashing) //设置常数时闪烁
{
if(flashing_time==0)
{
if(flashing_pb)
{
led_show_list[0]= encoder[constant_mtr[0]];
led_show_list[1]= encoder[constant_mtr[1]];
led_show_list[2]= encoder[constant_mtr[2]];
led_show_list[3]= encoder[constant_mtr[3]];
led_show_list[4]= 0;
led_show_list[5]= encoder[constant_cn];
flashing_time=170;
}
else
{
led_show_list[0]= encoder[constant_mtr[0]];
led_show_list[1]= encoder[constant_mtr[1]];
led_show_list[2]= encoder[constant_mtr[2]];
led_show_list[3]= encoder[constant_mtr[3]];
led_show_list[4]= 0;
led_show_list[5]= encoder[constant_cn];
led_show_list[current_flash_cn]=0; //消隐
flashing_time=30;
}
flashing_pb=!flashing_pb;
show_data();
}
return;
}
if(constant_all_flag=='A')
{
constant_all_flag=0;
led_show_list[0]= encoder[constant_mtr[0]];
led_show_list[1]= encoder[constant_mtr[1]];
led_show_list[2]= encoder[constant_mtr[2]];
led_show_list[3]= encoder[constant_mtr[3]];
led_show_list[4]= 0;
led_show_list[5]= encoder[constant_cn];
show_data();
return;
}
if(led_show_flag=='S')
{
//if((led_show_list[5]==0X3F)|(led_show_list[5]==0X00)) //消零
//{
// led_show_list[5]=0;
if((led_show_list[4]==0X3F)|(led_show_list[4]==0X00))
{
led_show_list[4]=0;
if((led_show_list[3]==0X3F)|(led_show_list[3]==0X00))
{
led_show_list[3]=0;
if((led_show_list[2]==0X3F)|(led_show_list[2]==0X00))
{
led_show_list[2]=0;
if((led_show_list[1]==0X3F)|(led_show_list[1]==0X00))
{
led_show_list[1]=0;
}
}
}
}
//}
show_data();
led_show_flag=0;
constant_showing=0;
}
}
/**************************************************************************************
*
* FUNCTION: main
*
* DESCRIPTION: 主程序
*
* PARAMETERS: none
*
* RETURNED: none
*
*************************************************************************************/
void main(void)
{
uchar i;
uchar j;
uchar k;
beep=0;
lamp=0;
for(i=0; i<10; i++) // 上电延时,等待电压稳定
{
WDT_RST=0xa1; // 清看门狗
for(j=0;j<255;j++);
}
initsys(); //初始化系统
led_dis_test(); //数码管显示测试程序
for(i=0; i<28; i++) //延时等候显示检测
{
for(j=0;j<200;j++)
{
WDT_RST=0xa1;
for(k=0; k<200; k++);
}
}
led_dis_clr();//数码管显示清屏程序
// led_dis_hello();//显示HELLO
current_flash_cn=3; //设置常数时闪烁数码管的位置。
lamp=1;
have_pulse=0; //bool变量
have_pulse_cn=0;
read_cs(); //读出全部常数和当前常数序号。
constant_all_flag='A';
constant_showing='S';
flash_stop=0;
key_cn=0;
an_set_left_cn=0;
an_set_right_cn=0;
an_set_up_cn=0;
an_set_down_cn=0;
an_start_cn=0;
an_stop_cn=0;
key_time=0;
while(1)
{
watchdog_reset=0x9a; //喂狗标志
initsys_ref(); //冗余初始化
do_key(); //按键处理,判断哪个按键按下了
do_check(); //处理检表开始
do_error(); //错误处理
//do_flash(); //处理灯闪烁
led_display(); //显示处理
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -