📄 液晶和按键.c
字号:
}
void display1( uchar x_add, uchar *dat1) //.数字
{
write_c( x_add );//1xxx,xxxx 设定DDRAM 7位地址xxx,xxxx到地址计数器AC
write_d( 0x2e+ 0 );
write_d( 0x30+ *dat1);
}
/*void display2( uchar x_add, uchar *dat1) //数字_
{
write_c( x_add );//1xxx,xxxx 设定DDRAM 7位地址xxx,xxxx到地址计数器AC
write_d( 0x30+ *dat1);
write_d( 0x20+ 0 );
} */
void CLR_line(uchar dz) /* 清除一行 */
{
uchar i;
for(i=0;i<2;i++)
{
write_c(dz);
write_d(' ');
Delay();
}
}
void t0_int(void) interrupt 1 //时间
{
TH0=0x4c;
TL0=0x00;
time++;
if(time==20)
{
time=0;
counts[3]++;
if(counts[3]==10)
{
counts[3]=0;
counts[2]++;
if(counts[2]==10)
{
counts[2]=0;
counts[1]++;
if(counts[1]==10)
{
counts[1]=0;
counts[0]++;
}
}
}
}
if((counts[0]==1)&&(counts[1]==2)&&(counts[2]==5)&&(counts[3]==1))
{
counts[0]=0;
counts[1]=0;
counts[2]=0;
}
/*****************
jj++;
if(jj==40)jj=0;
if(jj<=aa) input1=0;
else input1=1;
/****************/
}
void t1_int(void) interrupt 3 //PWM
{
/*TH1=0x4c;
TL1=0x00;
jj++;
if(jj==40)jj=0;
if(jj<=aa)input1=0;
else {input1=1; }*/
if(++count<=(high_time))
{input1=0;
input2=1;}
else if(count<=100)
{
input1=1;
input2=0;
}
else
count=0;
TH0=0x18;
TL0=0x10;
}
/*void add(void) interrupt 0 //温度+
{
Delay();
begin++;
if(m==1)begin=0;
m=0;
counts[0]=0;
counts[1]=0;
counts[2]=0;
counts[3]=0;
}
void sub(void) interrupt 2 //温度-
{
Delay();
begin--;
if(n==1)begin=99;
n=0;
counts[0]=0;
counts[1]=0;
counts[2]=0;
counts[3]=0;
} */
void delay10ms(void)
{
unsigned char i,j,k;
for(i=5;i>0;i--)
for(j=4;j>0;j--)
for(k=248;k>0;k--);
}
void getkey()
{
/*******************设定温度部分按键程序**********************/
if(add==0)
{
delay10ms();
delay10ms();
if(add==0)
{
begin++;
if(begin==99)begin=0;
counts[0]=0;
counts[1]=0;
counts[2]=0;
counts[3]=0;
}
}
while(add==0);
if(sub==0)
{
delay10ms();
delay10ms();
if(sub==0)
{
begin--;
if(begin==0)begin=99;
counts[0]=0;
counts[1]=0;
counts[2]=0;
counts[3]=0;
}
}
while(sub==0);
}
/*******************************************************************/
/*************************************************************/
/***************************PID算法**************************/
unsigned int PIDCalc( struct PID *pp, unsigned int NextPoint )
{
unsigned int dError,Error;
Error = pp->SetPoint - NextPoint; // 偏差
pp->SumError += Error; // 积分
dError = pp->LastError - pp->PrevError; // 当前微分
pp->PrevError = pp->LastError;
pp->LastError = Error;
return (pp->Proportion * Error
+ pp->Integral * pp->SumError
+ pp->Derivative * dError);
}
void compare_temper()
{
unsigned char i,s;
temper=Data[2]*10+Data[1];
s=begin;
if(s>temper)
{
if(s-temper>1)
{
high_time=100;
low_time=0;
}
else
{
for(i=0;i<10;i++)
{
ow_reset();
read_temp();
work_temp();
rin =(int)(Data[2]*10+Data[1]); // Read Input
rout = PIDCalc ( &spid,rin ); // Perform PID Interation
}
if (high_time<=100)
high_time=(unsigned char)(rout/800);
else
high_time=100;
low_time= (100-high_time);
}
}
else if(s<=temper)
{
if(temper-s>0)
{
high_time=0;
low_time=100;
}
else
{
for(i=0;i<10;i++)
{
ow_reset();
read_temp();
work_temp();
rin = (int)(Data[2]*10+Data[1]); // Read Input
rout = PIDCalc ( &spid,rin ); // Perform PID Interation
}
if (high_time<100)
high_time=(unsigned char)(rout/10000);
else
high_time=0;
low_time= (100-high_time);
}
}
}
/*****************************************************************/
void con_temp()
{
unsigned int shijian;
unsigned char wendu;
shijian=(int)(counts[1]*100+counts[2]*10+counts[3]);
wendu=Data[2]*10+Data[1];
if(shijian<250)
{
compare_temper();
}
if( (shijian>250)&&(shijian<350) )
{
if((wendu>39)&&(wendu<43))
{
// input2=0;
// input1=1;
begin=40;
compare_temper();
}
}
if(shijian>350) begin=50;
if((shijian>350)&&(shijian<=400))
{
compare_temper();
}
if( (shijian>400)&&(shijian<=415) )
{
input2=0;
input1=1;
}
if((shijian>415)&&(shijian<=465))
{
compare_temper();
}
if( (shijian>465)&&(shijian<=480) )
{
input2=0;
input1=1;
}
if((shijian>480)&&(shijian<=530))
{
compare_temper();
}
if( (shijian>530)&&(shijian<=545) )
{
input2=0;
input1=1;
}
if((shijian>545)&&(shijian<=565))
{
compare_temper();
}
if( (shijian>565)&&(shijian<=610) )
{
input2=0;
input1=1;
}
if((shijian>610)&&(shijian<850))
{
compare_temper();
}
if(shijian>851)
{
begin=40;
compare_temper();
}
if(((shijian>=875)&&(shijian<885))||((shijian>=925)&&(shijian<938))||((shijian>=990)&&(shijian<1001)))
{
dianji=0;
} else dianji=1;
if((shijian==250)||(shijian==350)||(shijian==650)||(shijian==850)||(shijian==1130))
{
beep=0;
} else beep=1;
/* if(((shijian>=5)&&(shijian<11))||((shijian>=25)&&(shijian<30))||((shijian>=35)&&(shijian<40)))
{
dianji=0;
} else dianji=1;*/
// if((shijian>870)&&(shijian<876)) dianji=0;
// else dianji=1;
}
void con_temp1()
{
if((counts[1]*100+counts[2]*10+counts[3])<351)
{compare_temper();}
if((counts[1]*100+counts[2]*10+counts[3])==351)
{
beep=0;
} else beep=1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -