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

📄 1210_key_disp.c

📁 320*240点阵液晶(sed1335)驱动程序,keil c调试通过,io连接方式
💻 C
字号:
#include "1210_Key_Disp.h"
#include "MSC1210.H"

#define uchar unsigned char
#define uint unsigned int

sbit P2_2 = P2^2;
sbit P2_3 = P2^3;
sbit P2_4 = P2^4;

unsigned char key_buff = 0;
unsigned char dis_buffer[] = {0, 1, 2, 3, 0xf, 5, 7, 8};
unsigned char seg[] = {	0x3f,	0x06,	0x5b,	0x4f,
						0x66,	0x6d,	0x7d,	0x07,
						0x7f,	0x6f,	0x77,	0x7c,
						0x39,	0x5e,	0x79,	0x71,
						0xbf,	0x86,	0xdb,	0xcf,
						0xe6,	0xed,	0xfd,	0x87,
						0xff,	0xef,	0xf7,	0xfc,
						0xb9,	0xde,	0xf9,	0xf1,

						0x80,	0x40,	0x00,	0x73,	0xc0};
//delay
void delay(int v)
{
	while(v != 0)	v --;
}


//dispunsigned char *disp_buffer
void disp(void)
{
	unsigned char i = 0,		j = 0;
	unsigned char temp_wei = 0x0,	temp_duan = 0;
	
	for(i = 0; i < 8; i ++)
	{
	     P2_3 = 0;  								//138---NO
	     temp_duan = seg[ *(dis_buffer + i) ] ;
	     for(j = 0; j < 8; j ++)
		{
			P2_2 = temp_duan & 0x80;
			temp_duan = temp_duan << 1;
			P2_4 =0;   P2_4 =1;       				//时钟
		}
		P2_3 = 1;
		P2 = (P2 & 0xf8) | temp_wei;
		temp_wei ++;
		delay(100);
	}
}


uchar key_enter(void)
{
	uchar conter = 0xfe;
	P2 = 0;
	while( conter != 0xdf )
	{
		P2 = conter;
		if( conter != P2 ) 							//如果不等,则有按键按下
		{           								//如果等,本行没有按键,考察其他行
			 return( 0xff );      					//有
		}
		conter =~ conter;
		conter =  conter << 1;
		conter =~ conter;
	}
       return(0x00);                 				//没有
}


unsigned char key4_12code(void)     				//扫描键码值
   {
   unsigned char hang = 0xfe, i, temp = 0;
   for(i = 0; i < 4; i ++)
     {
	     P2 = hang;        								//扫描信号
	     if( P2 != hang)
	      {
	          if( -( P2 - hang ) == 1)
	            return( 3 + temp );
	            else
	              if(-(P2-hang) == 2)
	              return( 2+temp );
	              else
	                 if(-(P2-hang) == 4)
	                 return( 1+temp );
	                 else
	                    if(-(P2-hang) == 8)
	          //          return(1+temp);
	            //        else
	              //         if(-(P1-hang)==0x10)
	                      return( 0+temp );
	     }
	     hang = ~hang;
	     hang =  hang << 1 ;
	     hang = ~hang;
	     temp =  temp + 4;
     }
   }
   
   
//键盘程序,开始等待按键,有了之后判断,判断之后等待松开,返回键值与印刷板一样。
uchar get_key(void)    
{
	uchar code keytemp_tab[] = {0xb, 7, 0xa, 0xff, 9, 6, 0xff, 2, 8, 0xff, 4, 1, 0xff, 5, 3, 0};
	uchar 		key_buffer = 0xff;
	while( key_enter() == 0)
           disp();
           {
	           key_buffer = key4_12code();
	           while(key_enter() != 0);
//	           		dis_buffer[0] = keytemp_tab[key_buffer];
			   		return( keytemp_tab[key_buffer] );
           }
}







⌨️ 快捷键说明

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