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

📄 kb.c

📁 简易彩色液晶键盘是带键盘的320*240 彩色液晶配合sw44b0综合测试程序。对于开发液晶键盘交互界面的驱动程序具有一定参考价值。
💻 C
字号:
#include <string.h>
#include "..\inc\def.h"
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\kb.h"
#include "..\inc\option.h"
#include "..\inc\def.h"
#include "..\inc\lcd.h"
#include "..\inc\lcdlib.h"
#include "..\inc\44blcd.h"
#include "..\inc\myplmm.h"

 //#define LOOP 1
#define XTOTAL 320
#define YTOTAL 240
#define EVERYX 32
#define HIGHB 32

 ; void clr_pf(char onebit);
void setb_pf(char onebit);
void clr_pg(char onebit);
void setb_pg(char onebit);
void displaylcd(char num);
void displaylcd32(char x, char y, char num,char type);
void clear(void);
void Lcd_kb_MonoInit(void);
void __irq keyboard(void);
////////////////////////////////////////////////
void ad_init (void);
////////////////////////////////////////////////


void __irq keyboard(void)
{
    char x=0,y=0,yrecord;
    rINTMSK=(BIT_GLOBAL|BIT_EINT3);
    Delay(200);
    Uart_Printf("come in,   \n");	 
    if((rPDATE&0xf0)==0xf0)
       {
    	      rPDATF=0X1f;
             rINTMSK=~(BIT_GLOBAL|BIT_EINT3);
	      rI_ISPC = BIT_EINT3;
	      return;
       	}
    else
    {  
       for (x=5; x<9; x++)
        {
         rPDATF=0X1ff;
         clr_pf(x);
         if ((rPDATE&0xf0) !=0xf0)
            {
             yrecord=(~((rPDATE&0xf0)>>4))&0xf;
	      for (y=0;  yrecord!=0; y++)  
		  { 
		   yrecord=(yrecord>>1);
		   }
	      setb_pf(x);
	      Uart_Printf("the key is %d  \n", (y+(x-5)*4-1));
	      Delay(100);
             switch(y+(x-5)*4-1)
	      {
	        case 0:
                            displaylcd32(255, 176, y+(x-5)*4-1, 0);
                            displaylcd32(160, 120, y+(x-5)*4-1, 1);
			        break;
		default: 
			       displaylcd32(255, 176, y+(x-5)*4-1, 0);
			       displaylcd32(160, 120, y+(x-5)*4-1, 1);
                             break;
	     }
	      rPDATF=0X1F;
	      rINTMSK=~(BIT_GLOBAL|BIT_EINT3);
	      rI_ISPC = BIT_EINT3;
	      return;
	      }
         setb_pf(x);
	  }
	  rPDATF=0X1F;
	  rINTMSK=~(BIT_GLOBAL|BIT_EINT3);
         rI_ISPC = BIT_EINT3;
  	  return;
    }
}

/*********************************************************/
 void setb_pf(char onebit)
{
//  rPCONF=(rPCONF&0x03ff)|(1<<10)|(1<<13)|(1<<16)|(1<<19) ;
  rPDATF=(rPDATF&0x1ff)|(0x1<<onebit);
}
/*********************************************************/
 void clr_pf(char  onebit)
{
  unsigned int i,s=0;
  for(i=0; i<onebit; i++)
  	{
  	s=(s|(0x1<<i));
  	}
  rPDATF=(rPDATF&0x1ff)&((0x1fe<<onebit)|s);    
}
/*********************************************************/
 void setb_pg(char onebit)
{
  rPCONG=(rPCONG&0x00ff)|0x5500;
  rPDATG=(rPDATG&0xff)|(0x1<<onebit);
}
/*********************************************************/
 void clr_pg(char  onebit)
{
  unsigned int i,s=0;
  for(i=0; i<onebit; i++)
  	{
  	s=(s|(0x1<<i));
  	}
  rPDATG=(rPDATG&0xff)&((0xfe<<onebit)|s);    
}
/*********************************************************/
void Test_Kb(void)
{
    
    int i=0,j=0; 
     rEXTINT=0x22222222;
    rINTCON=0x5;
    pISR_EINT3=(unsigned)keyboard;
    rPCONF=(rPCONF&0x03ff)|(1<<10)|(1<<13)|(1<<16)|(1<<19) ; //0x92400;  //rPCONG=(rPCONG&0x00ff)|0x5500;
  //  rPCONG=(rPCONG&0xff3f)|0x00c0;
  //  rPCONE=(rPCONE&0x30000)|0x5555;
  //  rPUPE=0;
 //   rPUPG=rPUPG&0xf7;
   
	  Lcd_kb_MonoInit();

	  clear();

    Uart_Printf(" S3C44B0X 键盘测试(液晶显示效果) \n");
    Uart_Printf("按下任意键液晶上有相应键值和图标显示!  \n");
    Uart_Printf("计算机键盘任意键退出!!!\n");	 
    
    rINTMSK =~(BIT_GLOBAL|BIT_EINT3); 
    while(!Uart_GetKey())
    { 
 /*     for (i=7; i<12; i++)
       { 
         displaylcd32(j, 208, 16, 0);                            // clear the last one bmp
          j=(i-7)*16;
	  displaylcd32(j, 208, i, 0);
         Delay(2200);
	 }
      for (i=12; i<17; i++)
       { 
         displaylcd32(j, 208, 16, 0);                            // clear the last one bmp
          j=(i-7)*16;
	  displaylcd32(j, 208, i-5, 0);
         Delay(2200);
	 }
      for (i=17; i<22; i++)
       { 
         displaylcd32(j, 208, 16, 0);                            // clear the last one bmp
          j=(i-7)*16;
	  displaylcd32(j, 208, i-10, 0);
         Delay(2200);
	 }
      for (i=22; i<24; i++)
       { 
         displaylcd32(j, 208, 16, 0);                            // clear the last one bmp
          j=(i-7)*16;
	  displaylcd32(j, 208, i-15, 0);
         Delay(2200);
	 }*/
    }
    rINTMSK|=BIT_EINT3;
}
/*********************************************************/
void Lcd_kb_MonoInit(void)
{
         #define MVAL_USED 0
     if((U32)frameBuffer256==0)
	{
	    frameBuffer256=(unsigned int (*)[SCR_XSIZE/4])malloc(ARRAY_SIZE_COLOR); 
	}

	rLCDCON1=(0)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
	    // disable,8B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
	rLCDCON2=(LINEVAL)|(HOZVAL_COLOR<<10)|(10<<21);  
	    //LINEBLANK=10 (without any calculation) 
	rLCDSADDR1= (0x3<<27) | ( ((U32)frameBuffer256>>22)<<21 ) | M5D((U32)frameBuffer256>>1);
	    // 256-color, LCDBANK, LCDBASEU
	rLCDSADDR2= M5D(((U32)frameBuffer256+(SCR_XSIZE*(LINEVAL+1)))>>1) | (MVAL<<21);
	rLCDSADDR3= (LCD_XSIZE/2) | ( ((SCR_XSIZE-LCD_XSIZE)/2)<<9 );

	//The following value has to be changed for better display.

	rREDLUT  =0xfdb97531;
	rGREENLUT=0xfdb97531;
	rBLUELUT =0xfb73;

	rDITHMODE=0x0;
	rDP1_2 =0xa5a5;      
	rDP4_7 =0xba5da65;
	rDP3_5 =0xa5a5f;
	rDP2_3 =0xd6b;
	rDP5_7 =0xeb7b5ed;
	rDP3_4 =0x7dbe;
	rDP4_5 =0x7ebdf;
	rDP6_7 =0x7fdfbfe;

	rLCDCON1=(1)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
} 
//
/*void Lcd_kb_MonoInit(void)
{
    //160x240 1bit/1pixel LCD
     #define MVAL_USED 0
   if((U32)frameBuffer1==0)
	{
	    if (( frameBuffer1=(unsigned int (*)[SCR_XSIZE/32])malloc(ARRAY_SIZE_MONO))==NULL)
	    {
	      Uart_Printf("ERROR !!!!!! NO MEMERY !!!!!!!!! \n");
	    }
	}
   
	rLCDCON1=(0)|(1<<5)|(0<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_MONO<<12);
	    // disable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
	rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21);  
	    //LINEBLANK=10 (without any calculation) 
	rLCDSADDR1= (0x0<<27) | ( ((U32)frameBuffer1>>22)<<21 ) | M5D((U32)frameBuffer1>>1);
	    // monochrome, LCDBANK, LCDBASEU
	rLCDSADDR2= M5D( (((U32)frameBuffer1+(SCR_XSIZE*LCD_YSIZE/8))>>1) ) | (MVAL<<21);
	rLCDSADDR3= (LCD_XSIZE/16) | ( ((SCR_XSIZE-LCD_XSIZE)/16)<<9 );
	rREDLUT  =0xfdb97531;
	rGREENLUT=0xfdb97531;
	rBLUELUT =0xfb73;

	rDITHMODE=0x0;
	rDP1_2 =0xa5a5;      
	rDP4_7 =0xba5da65;
	rDP3_5 =0xa5a5f;
	rDP2_3 =0xd6b;
	rDP5_7 =0xeb7b5ed;
	rDP3_4 =0x7dbe;
	rDP4_5 =0x7ebdf;
	rDP6_7 =0x7fdfbfe;

	rLCDCON1=(1)|(1<<5)|(0<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_MONO<<12);
	    // enable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
    
}*/
	
void displaylcd32(char x, char y, char num, char type)
{
    unsigned int *pbuffer,temp_data;
    unsigned int i=0, j=0, m=0;
     
    //clrscreen();
    pbuffer =(U32*) frameBuffer256;
    for(m=0; m<HIGHB; m++)
     { 
       i = (y+m)*XTOTAL*8/EVERYX+x*8/EVERYX;
	//Uart_Printf("the i is : %x   \n", i);
	if (type == 0)
		{
        temp_data = (Bitmap32[num][m*32] << 24) + (Bitmap32[num][m*32+1] << 16) + (Bitmap32[num][m*32+2] << 8) +(Bitmap32[num][m*32+3]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32[num][m*32+4] << 24) + (Bitmap32[num][m*32+5] << 16) + (Bitmap32[num][m*32+6] << 8) +(Bitmap32[num][m*32+7]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32[num][m*32+8] << 24) + (Bitmap32[num][m*32+9] << 16) + (Bitmap32[num][m*32+10] << 8) +(Bitmap32[num][m*32+11]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32[num][m*32+12] << 24) + (Bitmap32[num][m*32+13] << 16) + (Bitmap32[num][m*32+14] << 8) +(Bitmap32[num][m*32+15]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32[num][m*32+16] << 24) + (Bitmap32[num][m*32+17] << 16) + (Bitmap32[num][m*32+18] << 8) +(Bitmap32[num][m*32+19]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32[num][m*32+20] << 24) + (Bitmap32[num][m*32+21] << 16) + (Bitmap32[num][m*32+22] << 8) +(Bitmap32[num][m*32+23]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32[num][m*32+24] << 24) + (Bitmap32[num][m*32+25] << 16) + (Bitmap32[num][m*32+26] << 8) +(Bitmap32[num][m*32+27]);
       pbuffer[i]=temp_data;
	i++;
       temp_data = (Bitmap32[num][m*32+28] << 24) + (Bitmap32[num][m*32+29] << 16) + (Bitmap32[num][m*32+30] << 8) +(Bitmap32[num][m*32+31]);
       pbuffer[i]=temp_data;
	           }
	else 
		{
        temp_data = (Bitmap32_num[num][m*32] << 24) + (Bitmap32_num[num][m*32+1] << 16) + (Bitmap32_num[num][m*32+2] << 8) +(Bitmap32_num[num][m*32+3]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32_num[num][m*32+4] << 24) + (Bitmap32_num[num][m*32+5] << 16) + (Bitmap32_num[num][m*32+6] << 8) +(Bitmap32_num[num][m*32+7]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32_num[num][m*32+8] << 24) + (Bitmap32_num[num][m*32+9] << 16) + (Bitmap32_num[num][m*32+10] << 8) +(Bitmap32_num[num][m*32+11]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32_num[num][m*32+12] << 24) + (Bitmap32_num[num][m*32+13] << 16) + (Bitmap32_num[num][m*32+14] << 8) +(Bitmap32_num[num][m*32+15]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32_num[num][m*32+16] << 24) + (Bitmap32_num[num][m*32+17] << 16) + (Bitmap32_num[num][m*32+18] << 8) +(Bitmap32_num[num][m*32+19]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32_num[num][m*32+20] << 24) + (Bitmap32_num[num][m*32+21] << 16) + (Bitmap32_num[num][m*32+22] << 8) +(Bitmap32_num[num][m*32+23]);
       pbuffer[i]=temp_data;
	i++;
        temp_data = (Bitmap32_num[num][m*32+24] << 24) + (Bitmap32_num[num][m*32+25] << 16) + (Bitmap32_num[num][m*32+26] << 8) +(Bitmap32_num[num][m*32+27]);
       pbuffer[i]=temp_data;
	i++;
       temp_data = (Bitmap32_num[num][m*32+28] << 24) + (Bitmap32_num[num][m*32+29] << 16) + (Bitmap32_num[num][m*32+30] << 8) +(Bitmap32_num[num][m*32+31]);
       pbuffer[i]=temp_data;
		}
    	}	
	/*j=(pbuffer[i]>>(EVERYX- (x*8)%EVERYX))<<(EVERYX-(x*8)%EVERYX);
	pbuffer[i]=j|(temp_data>>((x*8)%EVERYX));
	//Uart_Printf("pbuffer[%d]= %x   \n", i, pbuffer[i]);   
	j=(pbuffer[i+1]<<((x*8)%EVERYX))>>((x*8)%EVERYX);
	pbuffer[i+1] = j|(temp_data<<(EVERYX-(x*8)%EVERYX));       // ~temp_data;  
       // Uart_Printf("pbuffer[%d]= %x   \n", i+1, pbuffer[i+1]);  
      }*/
}

void clear(void)
{ 
     unsigned int *pbuffer;
     int i;
     
    pbuffer =(U32*) frameBuffer256;
    for(i = 0; i< (9600*8/4) ;i++)
    {
        pbuffer[i] = 0;

 }

}

⌨️ 快捷键说明

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