⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 程控源.c

📁 实现电压电流的分别输出,可通过按键选择输出通道.
💻 C
字号:
/*******************************************************************************************************
程控源:key_s=P2_0;  key_p=P2_1;    key_n=P2_2;    
	开机时	电压显示:U-4.5
		电流显示:L-0.7
********************************************************************************************************/
#include <at89x52.h>

code unsigned char LedCode[13]=	{0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f,0x3e,0x38,0x40};  //U .I. -

sbit key1=P2^0;
sbit key2=P2^1;
sbit key3=P2^2; 

unsigned char s=0;
unsigned char Dout_U=90;      //2格为1个单位
unsigned char Dout_I=140;
unsigned char u=45;
unsigned char i=70;

unsigned char DH,DL;            


/*延时函数*/
void delay( unsigned int t)
{	
	unsigned int j;
	for(j=0;j<t;j++ );
}   

/*显示函数*/
void xianshi_U(void)
{		
		DH=u/10;
		DL=u%10;
		
		P0 = LedCode[ 10  ]; 			P2_4 = 0; 	delay(300);		P2_4=1;
		P0 = LedCode[ 12  ]; 			P2_5 = 0; 	delay(300);		P2_5=1;
		P0 = LedCode[ DH  ]|0x80; 		P2_6 = 0; 	delay(300);		P2_6=1;
		P0 = LedCode[ DL  ]; 			P2_7 = 0; 	delay(300);		P2_7=1; 
}	

void xianshi_L(void)
{	
		DH=i/10;
		DL=i%10;
		
		P0 = LedCode[ 11  ]; 			P2_4 = 0; 	delay(300);		P2_4=1;
		P0 = LedCode[ 12  ]; 			P2_5 = 0; 	delay(300);		P2_5=1;
		P0 = LedCode[ DH  ]|0x80; 		P2_6 = 0; 	delay(300);		P2_6=1;
		P0 = LedCode[ DL  ]; 			P2_7 = 0; 	delay(300);		P2_7=1; 
}

/**************电压输出*******************/
void dianya(void)
{
	if(key2==0) 
	{
		while(key2==0) xianshi_U();
		if(u<50)
		{
			Dout_U=Dout_U+2;
			u=u+1;
		}
	}

	if(key3==0)
	{
		while(key3==0) xianshi_U();	
		if(u>0)
		{
			Dout_U=Dout_U-2;
			u=u-1;
		}
	}
	P3=Dout_U;
}

/**************电流输出*******************/
void dianliu(void)
{
	
	if(key2==0) 
	{
		while(key2==0) xianshi_L();
		if(i<80)
		{
			Dout_I=Dout_I+2;
			i=i+1;
		}	
	}

	if(key3==0)
	{
		while(key3==0) xianshi_L();	
		if(i>0)
		{
			Dout_I=Dout_I-2;
			i=i-1;
		}
	}
	P3=Dout_I;	
}

/********   主程序   *******/
void main(void)
{	
	P2_3=0;
	while(1) 
	{   
		if(key1==0) 
		{
			if(s==0)
			{
				while(key1==0) xianshi_U();
			}

			if(s==1)
			{
				while(key1==0) xianshi_L();	
			}
			s=!s;
		}
		if(s==0) 
		{
			P2_3=0;
			dianya();
			xianshi_U();
		}
	    if(s==1) 
		{
			P2_3=1;
			dianliu();
			xianshi_L();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -