信号Рsbit DA-W=P2^3; //DA转换信号Рunsigned char ad_data; //AD采样值Рunsigned char count=0; //定时标记值Рchar e; //定义当前采样值Рchar u; //定义DA输出量Рchar u0=0;Рchar u1=0;Рchar e0=0;Рchar e1=0; //前两次采样值和前两次控制值Рfloat temp; //设置指针Рvoid AD() //AD采样函数Р{РStart=0;РStart=1; //启动AD转换器,开始转换РStart=0;Р while(EOC==0); //转换未结束,空循环Р?ad_data=P0; //转换结束后,读取AD输出值Р}Рvoid TimeInnitial() //定时器中断初始化函数Р{РTMOD=0X11; //定时器0采用方式1РTH0=0X3C; //设置定时器0初值РTL0=0XB0;РEA=1; //开中断РET0=1; //允许 T0溢出中断РTR0=1; //开定时器T0Р}Рvoid main() //主函数Р{Р?TimeInitial();Р Start=0; //启动信号为0Р?DA-W=0; Р P1=0x80;РDA-W=1; //控制器初始输出为0РWhile(1); //空循环,等待中断Р}Рvoid t1(void)interrupt 1 using 1 //定时器T0中断函数Р{Р?TH0=0x3c;Р?TL0=0xb0; //重装初值Р?if(count==2) //采样周期为0.1sР?{Р count=0;Р AD(); //0.1s后,读取AD采样值Р e=ad_data-128; //采样实际偏差值Р temp=0.27*u1+0.7*u0+26.18*e-39.28*e1+14.2*e0;?//差分方程