致 谢
附录A: 系统主体程序:
/*A/D转换驱动*/
uint Read_tlc2543dat(uchar port) //port代表通道,可以为0-10的任意通道 {
uchar i; uint ad=0; ioclk=0; cs2543=1; cs2543=0;
port<<=4;//写数据port=0-10,这句要;
21
写port=0x00-0xb0,这句不要。由于TLC2543是12位的,所以Datasheet上的8位与16位没意义。
for(i=0;i<12;i++) {
if(dout2543) ad|=0x01; din2543=(bit)(port&0x80); ioclk=1; ioclk=0;
port<<=1;
ad<<=1;
} cs2543=1; ad>>=1; return(ad); }
}
pwm++;
/*MPPT算法程序*/ void mppt() {
uchar P_new,U_new; if(P>P_new) { } else { }
if(U>U_new) else
PWM++; PWM--; if(U>U_new) else
PWM--; PWM++;
/*PWM波产生程序*/ void Init_pwm() {
TMOD|= 0x11;//PWM
TH1 = 0xff; //11.0592 TL1 = 0xff; TR1 = 1;
IE =0x8A; }
void pwm() {
Init_pwm(); if(pwm>100)
pwm=0;
}
if(pwm pwm_out=1; } else pwm_out=0; /*主函数*/ void main() { uint ad0,ad1,U,I,P,num; Init_n5110(); Clear_n5110(); while(1) { uchar i; void timer1 () interrupt 3 //3 为定时器1的中断号 1 定时器0的中断号 0 外部中断1 2 外部中断2 4 串口中断 { TH1 = 0xff; //11.0592 TL1 = 0xff; 22 ad0=Read_tlc2543dat(0); ad1=Read_tlc2543dat(1); U=(float)((4.096*ad0)/4095*1127+113); //综合几组数据得到分压比系数为11.27,再加113,降低误差 I=(float)((4.096*ad1)/4095*100);// 通道0采样的是电流 } } pwm(); mppt(); P=(float)U*(float)I/100; display(P/*,I,P*/); 附录B: 系统实物图: 图B1 23 图B2 图B3 24