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

📄 text1.c

📁 简单的树数控直流电源程序
💻 C
字号:
/*******************************************法一**********************************/

#include<reg52.h>

#define	uchar unsigned char 
#define uint unsigned int 

uchar dispcode[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
//uchar dispbitcode[]={0xdf,0xbf,0x7f};
uchar dispbuf[]={0,0,0};

uchar h=0,dispbitcnt=0;

sbit P3_0=P3^0;
sbit P3_1=P3^1;
sbit P3_2=P3^2;
sbit P3_3=P3^3;
sbit P3_4=P3^4;
sbit P3_5=P3^5;
sbit P3_6=P3^6;
sbit P3_7=P3^7;

void keyboard();

void initTimer(void)
	{
	   TMOD=0x00;
   	   TH0=0xc1;
   	   TL0=0x18;
  	   EA=1;
  	   ET0=1;
   	   TR0=1;
	}	

void delay10ms()				 //延时函数
    {
 		unsigned char i,j;
 		for(i=0;i<248;i++)
 		for(j=0;j<10;j++);
	}

void main()
	{	
		
		initTimer();
		switch(dispbitcnt)
				{
					case 0:{P3_5=1;P3_6=0;P3_7=0;}break;
					case 1:{P3_5=0;P3_6=1;P3_7=0;}break;
					case 2:{P3_5=0;P3_6=0;P3_7=1;}break;
					break;
				}
		P1=dispcode[dispbuf[dispbitcnt]];
		dispbitcnt=(dispbitcnt+1)%3;
		while(1)
			{
	 			P3_0=1;P3_1=1;P3_2=1;P3_3=1;
				if((P3&0x0f)!=0x0f)	keyboard();
				P3_4=1;
				P0=h;
				P3_4=0;
		 	}
	}

void keyboard()
	{
		unsigned char temp;
		if((P3&0x0f)!=0x0f)	delay10ms();
		if((P3&0x0f)!=0x0f)	temp=P3&0x0f;
			switch(temp)
				{
				 	case 0x0e:{h=(h+1)%151;while((P3&0x0f)==0x0e);}break;
				 	case 0x0d:{if(h>=0)h--;while((P3&0x0f)==0x0d);}break;
				 	break;
				}	
	}

void t0(void) interrupt 1
	{
	 	TH0=0xc1;
   	 	TL0=0x18;	 	 
		 	dispbuf[2]=h/100;dispbuf[1]=(h%100)/10;dispbuf[0]=h%10;
			//P1=0x00;
			P1=dispcode[dispbuf[dispbitcnt]];
			switch(dispbitcnt)
				{
					case 0:{P3_5=1;P3_6=0;P3_7=0;}break;
					case 1:{P3_5=0;P3_6=1;P3_7=0;}break;
					case 2:{P3_5=0;P3_6=0;P3_7=1;}break;
					break;
				}
			dispbitcnt=(dispbitcnt+1)%3;	 	
	}




/*********************法二*****************/
/*
#include<reg51.h>

#define	uchar unsigned char 
#define uint unsigned int 

uchar dispcode[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
uchar dispbitcode[]={0xdf,0xbf,0x7f};
uchar dispbuf[]={0,0,0};

uchar h=0,dispbitcnt=0;

sbit P3_0=P3^0;
sbit P3_1=P3^1;
sbit P3_2=P3^2;
sbit P3_3=P3^3;
sbit P3_4=P3^4;
sbit P3_5=P3^5;
sbit P3_6=P3^6;
sbit P3_7=P3^7;

void keyboard();

void initTimer(void)
	{
	   TMOD=0x00;
   	   TH0=0xe0;
   	   TL0=0x18;
  	   EA=1;
  	   ET0=1;
   	   TR0=1;
	}	

void delay10ms()				 //延时函数
    {
 		unsigned char i,j;
 		for(i=0;i<248;i++)
 		for(j=0;j<5;j++);
	}

void main()
	{	
		
		initTimer();
		P2=dispbitcode[dispbitcnt];
	    P1=dispcode[dispbuf[dispbitcnt]];
		dispbitcnt=(dispbitcnt+1)%3;
		while(1)
			{
	 			P3=0xff;
	 			if(P3!=0xff)	keyboard();
				P3_4=1;
				P0=h;
				P3_4=0;
		 	}
	}

void keyboard()
	{
		unsigned char temp;
		if(P3!=0xff)	delay10ms();
		if(P3!=0xff)	temp=P3;
			switch(temp)
				{
				 	case 0xfe:{h=(h+1)%151;while(P3==0xfe);}break;
				 	case 0xfd:{if(h>=0)h--;while(P3==0xfd);}break;
				 	break;
				}	
	}

void t0(void) interrupt 1
	{
	 	TH0=0xe0;
   	 	TL0=0x18;	 	 
		 	dispbuf[2]=h/100;dispbuf[1]=(h%100)/10;dispbuf[0]=h%10;
				P2=dispbitcode[dispbitcnt];
				P1=dispcode[dispbuf[dispbitcnt]];
					dispbitcnt=(dispbitcnt+1)%3;	 	
	}	   */

⌨️ 快捷键说明

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