정적 디지털 파이프 디스플레이, 동적 디지털 파이프 디스플레이, 매트릭스 버튼

//       
#include "reg52.h"			 
typedef unsigned int u16;	
typedef unsigned char u8;

u8 code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
		0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//  0~F  
void main()
{	
	P0=~smgduan[0];//  0
	while(1);
}
//       

#include "reg52.h"	

typedef unsigned int u16;	
typedef unsigned char u8;

sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;

u8 code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
					0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//  0~F  

void delay(u16 i)
{
	while(i--);	
}//i=1 ,    10us

void DigDisplay()//         ,    8      
{
	u8 i;
	for(i=0;i<8;i++)
	{
		switch(i)	 //  ,        ,
		{
			case(0):
				LSA=0;LSB=0;LSC=0; break;//   0 
			case(1):
				LSA=1;LSB=0;LSC=0; break;//   1 
			case(2):
				LSA=0;LSB=1;LSC=0; break;//   2 
			case(3):
				LSA=1;LSB=1;LSC=0; break;//   3 
			case(4):
				LSA=0;LSB=0;LSC=1; break;//   4 
			case(5):
				LSA=1;LSB=0;LSC=1; break;//   5 
			case(6):
				LSA=0;LSB=1;LSC=1; break;//   6 
			case(7):
				LSA=1;LSB=1;LSC=1; break;//   7 	
		}
		P0=smgduan[i];//    
		delay(100); //        	
		P0=0x00;//  ********************************
	}
}

void main()
{	
	while(1)
	{	
		DigDisplay();
	}		
}
//    
/*    :          0,                 
			S1-S4:0-3
			S5-S8:4-7
			S9-S12:8-B
			S13-S16:C-F。

*/
#include "reg52.h"	

typedef unsigned int u16;	
typedef unsigned char u8;

#define GPIO_DIG P0
#define GPIO_KEY P1

u8 KeyValue;	//          

u8 code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
					0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//  0~F  

void delay(u16 i)
{
	while(i--);	
}

void KeyDown(void)//            
{
	char a=0;
	GPIO_KEY=0x0f;
	if(GPIO_KEY!=0x0f)//        
	{
		delay(1000);//  10ms    
		if(GPIO_KEY!=0x0f)//          
		{	
			//   
			GPIO_KEY=0X0F;
			switch(GPIO_KEY)
			{
				case(0X07):	KeyValue=0;break;
				case(0X0b):	KeyValue=1;break;
				case(0X0d):     KeyValue=2;break;
				case(0X0e):	KeyValue=3;break;
			}
			//   
			GPIO_KEY=0XF0;
			switch(GPIO_KEY)
			{
				case(0X70):	KeyValue=KeyValue;break;
				case(0Xb0):	KeyValue=KeyValue+4;break;
				case(0Xd0):     KeyValue=KeyValue+8;break;
				case(0Xe0):	KeyValue=KeyValue+12;break;
			}
			while((a<50)&&(GPIO_KEY!=0xf0))	 //        
			{
				delay(1000);
				a++;
			}
		}
	}
}

void main()
{	

	while(1)
	{	
		KeyDown();
		GPIO_DIG=~smgduan[KeyValue];
	}		
}

좋은 웹페이지 즐겨찾기