m0_57655920
m0_57655920
采纳率100%
2021-05-04 20:28

数控直流稳压电源设计

求大神指点,该如何讲解电路原理,程序在下面

本系统的主要功能如下:

(1)输出电压:范围 0~+9.9V,步进 0.1V,纹波不大于 10mV;

(2)输出电流:500mA;  

(3)输出电压值由数码管(或 LCD)显示;  

(4)由“+”、“-”两键分别控制输出电压步进增减;

(5)直流电源输出±15V,+5V。

(6)输出电压可预置在 0~9.9V 之间的任意一个值;  

(7)用自动扫描代替人工按键,实现输出电压变化(步进 0.1V 不变);

 

#include<reg51.h>
#include<math.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P2^4;
sbit rw=P2^5;
sbit ea=P2^6;
uchar num,i,key,j=0;
float a2;
uchar keyscan(void);
uchar code table[6]="Please";
uchar code table1[16]=" enter letter...";
uchar code table2[16]="0123456789abcde.";
float  table3[6];
uchar code table4[8]="volt(v):";
uchar code table5[6]="error!";
uchar  table6[6];
void delay(uint z)
{
 uint x,y;
 for(x=z;x>0;x--)
  for(y=110;y>0;y--); 
}

void write_com(uchar com)
{
 rs=0;	   
 rw=0;	  
 P0=com;
 delay(5);
 ea=1;		
 delay(5);
 ea=0;
}
void write_date(uchar date)
{
 rs=1;		
 rw=0;
 P0=date;
 delay(5);
 ea=1;
 delay(5);
 ea=0;
}
void disvol()
{
		write_com(0x80+0x40);	 	
		for(num=0;num<8;num++)	 
		   {
		    write_date(table4[num]); 
		    delay(10);
		   }		
}
  
void init()
{
 delay(5);
 write_com(0x38);
 write_com(0x0c);
 write_com(0x06);
 write_com(0x01);
 write_com(0x80);
 for(num=0;num<6;num++)
  {
   write_date(table[num]);	  
   delay(20);
  }
 write_com(0x80+0x40);   
 for(num=0;num<0x10;num++)	 
  {
    write_date(table1[num]);   
    delay(20);
   }
}

void diserr()
{
	   write_com(0x80+0x40);	
	   for(num=0;num<6;num++)
	   {
	    write_date(table5[num]);	
		delay(20);
	   }
	   delay(2000);	
} 

void he_zhi()
{
 uint a1,a3,c11,c12;
 float b1,b2,b3,b4,c1,c2,h;
 if(table3[0]!='.')	   
 {
	 if(!table3[1])
	 {
	 	if(j==1)
		{
	 		table3[1]='.';
		}
	 }
	 if(!table3[2])
	 {
	 	if(j==2)
		{
			table3[2]='.';
		}
	 }
 if(table3[1]=='.')
	 {	 
		 b1=table3[0];
		 b2=table3[2]/10;
		 b3=table3[3]/100;
		 h=b1+b2+b3;
		 a2=h*256/10;
		 a3=a2;
		 a1=a3+1;
		 c1=a2-a3;
		 c2=a1-a2;
		 c11=1000*c1;
		 c12=1000*c2;
		 if(c11>c12)
		 {
		 P1=a1;
		 }
		 else
		 {
		  P1=a3;
		 }		
		 if(j==1)
		 {
		 	write_com(0x80+0x49);	
		 }					  
		 if(j==3)
		 {
		 	write_com(0x80+0x4b);
		 }
		 if(j==4)
		 {
		 	write_com(0x80+0x4c);
		 }		  
	 }
else if(table3[2]=='.')
	 {	  
		  b1=table3[0]*10;
		  b2=table3[1];
		  b3=table3[3]/10;
		  b4=table3[4]/100;
		  h=b1+b2+b3+b4;
		  if(h<=10)
	  {
				 a2=h*256/10;
				 a3=a2;
				 a1=a3+1;
				 c1=a2-a3;
				 c2=a1-a2;
				 c11=1000*c1;
				 c12=1000*c2;
				 if(c11>c12)
				 {
					 P1=a1;
				 }
				 else		 
				 {
					 if(a3==256)  
					 {
					     P1=255;
					 }
					 else		   
					 {
					   	 P1=a3;
					 }
				 }				  
		 if(j==2)
		 {
		 	write_com(0x80+0x4a);	
		 }

	}		 
			 else 
			  {
			  		write_com(0x01);
					diserr();		
			  }	
	}
	else
		{
			write_com(0x01);
			diserr();	
		}
}
	if(table3[0]=='.')
	{
	   write_com(0x01);
	   diserr();		
	}
	
}
void qingchu(uchar p)
{	
	uchar z;
	for(z=0;z<=5;z++)
	{
	table3[z]=p;
	} 
}
void main()
{
 init();
 
 delay(4500);
 write_com(0x01);
 write_com(0x80+0x40);
 write_com(0x0f);
 disvol();
 i=0x80+0x48;

 while(1)
{
 key=keyscan();			  
 delay(100);
 switch(key)
{	 
  case 0xee:write_com(i);
           write_date(table2[0]);table3[j]=0;j++;	 //  table2[16]="0123456789abcde." 
			i++;
			break;//0 
  case 0xde:write_com(i);
            write_date(table2[1]);table3[j]=1;j++;
			i++;
			break;//1
  case 0xbe:write_com(i);
            write_date(table2[2]);table3[j]=2;j++;
			i++;break;//2
  case 0x7e:write_com(i);
            write_date(table2[3]);table3[j]=3;j++;
			i++;break;//3
  case 0xed:write_com(i);
            write_date(table2[4]);table3[j]=4;j++;
			i++;break;//4
  case 0xdd:write_com(i);
            write_date(table2[5]);table3[j]=5;j++;
			i++;break;//5
  case 0xbd:write_com(i);
            write_date(table2[6]);table3[j]=6;j++;
			i++;break;//6
  case 0x7d:write_com(i);
            write_date(table2[7]);table3[j]=7;j++;
			i++;break;//7
  case 0xeb:write_com(i);
            write_date(table2[8]);table3[j]=8;j++;
			i++;break;//8
  case 0xdb:write_com(i);
            write_date(table2[9]);table3[j]=9;j++;
			i++;break;//9
  case 0xe7:write_com(i);
            write_date(table2[15]);table3[j]='.';j++;
			i++;break; 
  case 0xbb:write_com(i);
			 table3[j]=table3[j]+0.1 ;
			 break;
  case 0xd7:he_zhi();
 			i=0x80+0x48;  
			j=0;	  
			break;
  case 0xb7:write_com(0x01);
			qingchu(0);
			j=0;
			disvol();
			write_com(0x80+0x48);
			i=0x80+0x48;
			break;
 }
 }
}
uchar keyscan(void)
{
 uchar cord_h,cord_l;
 P3=0x0f;            
 cord_h=P3&0x0f;     
 if(cord_h!=0x0f)    
 {
  delay(100);        
  if(cord_h!=0x0f)
  {
    cord_h=P3&0x0f;  
    P3=cord_h|0xf0; 
    cord_l=P3&0xf0;  
    return(cord_h+cord_l);
   }
  }return(0xff);    
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

相关推荐