📄 ceshi2.c
字号:
led_show_list[4]=0x00;
led_show_list[5]=0x00;
led_show_flag='S';
current_type='D'; //当前待测表为电子表
an_start_flag=0x00;
flash_flag=0x00;
relay=0;
// lamp_cs=0; //常数指示灯
// lamp_wc=1; //误差指示灯
}
if(an_set_jx_cn >= 5 )
{
an_set_jx_cn=0;
key_time=200;
if(showing=='J')
{jx_cs_cn++;
}
else
{showing='J';
}
if(jx_cs_cn >= 8)
{jx_cs_cn=0;
}
i=jx_cs_cn+jx_cs_cn+jx_cs_cn+jx_cs_cn;
led_show_list[0]=encoder[jx_cs_list[i+3]];
led_show_list[1]=encoder[jx_cs_list[i+2]];
led_show_list[2]=encoder[jx_cs_list[i+1]];
led_show_list[3]=encoder[jx_cs_list[i]];
led_show_list[4]=0x00;
led_show_list[5]=0x00;
led_show_flag='S';
current_type='J'; //当前待测表为机械表
an_start_flag=0x00;
flash_flag=0x00;
relay=0;
// lamp_cs=0; //常数指示灯
//lamp_wc=1; //误差指示灯
}
if(an_start_cn >= 5 )
{
key_time=200;
if(an_start_flag!='D')
{ an_start_flag='D';
check_step=0x00;
// flash_flag='F';
}
//else
//{ an_start_flag=0x00;
//flash_flag=0x00;lamp_cs=0;
//}
//lamp_cs=1; //常数指示灯
//lamp_wc=0; //误差指示灯
}
}
/**************************************************************************************
*
* FUNCTION: wc_over
*
* DESCRIPTION: 误差溢出数码管显示'E'.
*
* PARAMETERS: none
*
* RETURNED: none
*
*************************************************************************************/
void wc_over(void) //
{
led_show_list[0]=0x79;
led_show_list[1]=0x0;
led_show_list[2]=0x0;
led_show_list[3]=0x0;
led_show_list[4]=0x0;
led_show_list[5]=0x0;
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: do_check
*
* DESCRIPTION: 处理检表开始
*
* PARAMETERS: none
*
* RETURNED: none
*
*************************************************************************************/
void do_check(void)
{ uint i;
if(an_start_flag=='D')
{
if(check_step==0)
{
check_step=1;
relay=1; //闭合继电器
pulse_bz_cn=0x00;
pulse_dz_cn=0x00;
pulse_jx_cn=0x00;
pulse_bz_time=0x00;
pulse_dz_time=0x00;
pulse_jx_time=0x00;
pulse_bz_t=0x00;
pulse_dz_t=0x00;
pulse_jx_t=0x00;
pulse_bz_flag=0x00;
pulse_dz_flag=0x00;
pulse_jx_flag=0x00;
check_pulse='C'; //可以判断有无脉冲
check_time=CHECK_TIME; //
error=0; //出错
}
else
if(check_step==1)
{
if(check_pulse=='F')
{
check_pulse=0x00;
pulse_bz_cn--;
pulse_bz_time*=100; //标准表脉冲时间间隔的100倍
pulse_bz_time/=pulse_bz_cn;
if(current_type=='D')
{
pulse_dz_cn--;
pulse_dz_time*=100;
switch(dz_cs_cn)
{
case 0:
pulse_dz_cn*=1;break;
case 1:
pulse_dz_cn*=2;break;
case 2:
pulse_dz_cn*=4;break;
case 3:
pulse_dz_cn*=8;break;
default:
break;
}
pulse_dz_time/=pulse_dz_cn;
if(pulse_dz_time<=pulse_bz_time)
{
sign_flag='+';
i=pulse_bz_time-pulse_dz_time;
}
else
{
sign_flag='-';
i=pulse_dz_time-pulse_bz_time;
}
if(i>pulse_bz_time)
{wc_over(); //误差过大,数码管显示'E'
}
else
{ wc_show(i,pulse_bz_time); //显示误差
}
an_start_flag='D'; //继续检测
check_step=0x00;
showing=0; //当前显示的不是常数.
}
}
if(check_time ==0) //5秒之内脉冲太少
{
error='E';
an_start_flag='D'; //继续检测
check_step=0x00;
}
if(!((current_type=='D')|(current_type=='J'))) //没选取表计常数
{ wc_over();
}
}
}
}
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';
}
}
/**************************************************************************************
*
* FUNCTION: led_display
*
* DESCRIPTION: 数码管显示处理
*
* PARAMETERS: none
*
* RETURNED: none
*
*************************************************************************************/
void led_display(void)
{
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;
}
}
}
}
//}
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: main
*
* DESCRIPTION: 主程序
*
* PARAMETERS: none
*
* RETURNED: none
*
*************************************************************************************/
void main(void)
{
uchar i;
uchar j;
uchar k;
beep=0;
relay=0;
lamp_cs=0;
lamp_wc=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++);
}
}
lamp_cs=1;
lamp_wc=1;
led_dis_clr();//数码管显示清屏程序
led_dis_hello();//显示HELLO
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 + -