定时器程序设计如下:
#include<stdio.h>
#include<windows.h>
int T1=20;
int T2=300;
int k=0;
int numlast=0;
intin_data[926]={0};
int out_data=0;
int main (void)
{
int i=0;
FILE* KFILE = NULL;
KFILE = fopen("C:\\Users\\hp\\Desktop\\程序\\data_in.txt","r");//打开数据文件
FILE* fpWrite = NULL;
fpWrite =fopen("C:\\Users\\hp\\Desktop\\程序\\data_out.xls", "w");//输出结果
for (i = 0; i < 926; i++)
{
fscanf(KFILE, "%d\n", &in_data[ i]);//[ i]将文件中的输入值赋给in_data
[ i] if(in_data[ i]==1)
{
if((i-k)==T1)
{
out_data=1;
k=0;
numlast=i;
}
else if(i-numlast>=T2)
{
out_data=1;
numlast=i;
k=i;
}
else
out_data=0;
}
else
out_data=0;
fprintf(fpWrite, "%d\t%d\n", in_data[ i],out_data );
}
if(fclose(KFILE) != 0)
printf("error in closing filedata_in.txt");
if (fclose(fpWrite) != 0)
printf("error in closing filedata_out.xls");
return 0;
}
|