high_time=100;
low_time= (100-high_time); } }
else if(set_temper<=temper) {
if(temper-set_temper>0) {
high_time=0; low_time=100; } else {
for(i=0;i<10;i++) { get_temper(); rin = s; // 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); } } // else // {} }
/*****************************************************
T0中断服务子程序,用于控制电平的翻转 ,40us*100=4ms周期 ******************************************************/ void serve_T0() interrupt 1 using 1 {
if(++count<=(high_time)) output=1;
else if(count<=100) { output=0; } else count=0; TH0=0x2f;
TL0=0xe0; }
/***************************************************** 串行口中断服务程序,用于上位机通讯
******************************************************/ void serve_sio() interrupt 4 using 2 { /* EA=0; RI=0; i=SBUF; if(i==2) {
while(RI==0){} RI=0;
set_temper=SBUF; SBUF=0x02; while(TI==0){} TI=0; }
else if(i==3) { TI=0;
SBUF=temper; while(TI==0){} TI=0; } EA=1; */ }
void disp_1(unsigned char disp_num1[6]) {
unsigned char n,a,m; for(n=0;n<6;n++) {
// k=disp_num1[n]; for(a=0;a<8;a++) { clk=0;
m=(disp_num1[n]&1);
disp_num1[n]=disp_num1[n]>>1; if(m==1) data1=1; else
data1=0; _nop_(); clk=1; _nop_(); } } }
/***************************************************** 显示子程序
功能:将占空比温度转化为单个字符,显示占空比和测得到的温度 ******************************************************/ void display() {
unsigned char code number[]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6}; unsigned char disp_num[6]; unsigned int k,k1; k=high_time; k=k00; k1=k/100; if(k1==0) disp_num[0]=0; else
disp_num[0]=0x60; k=k0;
disp_num[1]=number[k/10]; disp_num[2]=number[k]; k=temper; k=k0;
disp_num[3]=number[k/10]; disp_num[4]=number[k]+1; disp_num[5]=number[s/10]; disp_1(disp_num); }
/*********************************************************** 主程序
***********************************************************/ main() {
unsigned char z;
unsigned char a,b,flag_2=1,count1=0;
unsigned char phil[]={2,0xce,0x6e,0x60,0x1c,2}; TMOD=0x21;
TH0=0x2f; TL0=0x40; SCON=0x50; PCON=0x00; TH1=0xfd; TL1=0xfd; PS=1; EA=1; EX1=0; ET0=1; ES=1; TR0=1; TR1=1; high_time=50; low_time=50;
PIDInit ( &spid ); // Initialize Structure spid.Proportion = 10; // Set PID Coefficients spid.Integral = 8; spid.Derivative =6;
spid.SetPoint = 100; // Set PID Setpoint while(1) {
if(plus==0) { EA=0;
for(a=0;a<5;a++) for(b=0;b<102;b++){} if(plus==0) {
set_temper++; flag=0; } }
else if(subs==0) {
for(a=0;a<5;a++) for(b=0;a<102;b++){} if(subs==0) {
set_temper--; flag=0; }
}
else if(stop==0) {
for(a=0;a<5;a++) for(b=0;b<102;b++){} if(stop==0) { flag=0; break; } EA=1; }
get_temper(); b=temper; if(flag_2==1) a=b;
if((abs(a-b))>5) temper=a; else temper=b; a=temper; flag_2=0; if(++count1>30) { display(); count1=0; }
compare_temper(); } TR0=0; z=1; while(1) { EA=0; if(stop==0) {
for(a=0;a<5;a++) for(b=0;b<102;b++){} if(stop==0) disp_1(phil); // break; }