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

📄 lm3033_keyboard.c

📁 TOPWAR LM3033及4X4矩阵键盘实现代码。实现字符型LCD及矩阵键盘库
💻 C
📖 第 1 页 / 共 2 页
字号:
    //send 4 "0"
    for(i = 0;i < 4;i ++) {
        LCD_SID_CLR;
        LCD_SCLK_SET;
        LCD_SCLK_CLR; 
    }
    //send data low 4 bits
    for(i = 3;i >= 0;i --) {
        if(data&(1<<i)) //current bit is "1"
            LCD_SID_SET;     
        else            //current bit is "0"
            LCD_SID_CLR; 
        LCD_SCLK_SET;
        LCD_SCLK_CLR;
    }
    //send 4 "0"
    for(i = 0;i < 4;i ++) {
        LCD_SID_CLR;
        LCD_SCLK_SET;
        LCD_SCLK_CLR; 
    }
}
/************************************************************************************************
Function:	  LCD_Coordinate
Description:set the display address
Calls:			- LCD_WriteChar
Input:			- U8 x(line select 0~3),U8 y(column select 0~7); 
Output:			- None
Return:			- None
**************************************************************************************************/
void LCD_Coordinate(U8 x, U8 y)  
 {                                                 
    U8 addr;
    //find address
  	switch(x)
  	{
        case 0: 
            addr = 0x80 + y; //line 0;column y
            break;
        case 1: 
            addr = 0x90 + y; //line 1;column y
            break;
        case 2: 
            addr = 0x88 + y; //line 2;column y
            break;
        case 3: 
            addr = 0x98 + y; //line 3;column y
            break;	
  	}
  	//setting command
  	LCD_WriteChar(0,addr);	
}
/************************************************************************************************
Function:	  LCD_write_string
Description:write a byte to the lcd , command or data
Calls:			- LCD_WriteChar/LCD_Coordinate
Input:			- U8 x(line select 0~3),U8 y(column select 0~7); U8 *str   string
Output:			- None
Return:			- None
**************************************************************************************************/
void LCD_write_string(U8 x,U8 y,U8 *str)
{
    //set adress
    LCD_Coordinate(x,y);
	  delay_Nms(1);   
	  while (*str!='\0')
	  {
	      LCD_WriteChar(1,*str);
		   delay_N100us(1);////////// delay_Nms(1);
		    str++;
		} 
}
/************************************************************************************************
Function:	  Number_Output
Description:output a 16 bits number to the lcd ,address decided by the coordinate user setted
Calls:			- LCD_WriteChar/LCD_Coordinate
Input:			- U8 x(line select 0~3),U8 y(column select 0~7); U16 number  number to be display
Output:			- None
Return:			- None
**************************************************************************************************/
void Number_Output(U16 number,U8 x,U8 y) {
   U16 bit_current,temp,temp_count,count;
   U16 bit_less;
   temp = number;
   count = 1;
   
   do{
      bit_current = temp%10;        //get current lowest bit
      bit_less    = temp/10;        //get bit less
      //output current bit number
      LCD_Coordinate(x,y);
      for(temp_count= count;temp_count>0;temp_count--)
        LCD_WriteChar(1,0x20);
      LCD_WriteChar(1,bit_current+0x30);
      y--;
      count++;
      //LCD_Coordinate(x,y);
      //LCD_WriteChar(1,0x20);
      temp=bit_less;
   }while(bit_less);         //while bit less is not equaled  to 0,then recycle
} 
/************************************************************************************************
Function:	  ScreenClean
Description: write 0x00 to the whole RAM for blank display
Calls:			- LCD_WriteChar
Input:			- None
Output:			- None
Return:			- None
**************************************************************************************************/
void ScreenClean(void) 
{
	U8 TempData = 0x00;
	U8 i, j;
	
  for(i=0;i<0x20;i++)
  {

  	LCD_WriteChar(0,0x34);// 8bit I/F, extend command        
  	LCD_WriteChar(0,0x80|i);// Y address
  	LCD_WriteChar(0,0x80);  // X address  
    LCD_WriteChar(0,0x36);  // 8bit I/F, basic command, graphic on
    for(j=0;j<0x10;j++)
   	{
   		 LCD_WriteChar(1,TempData);
   		 LCD_WriteChar(1,TempData);     		
	  }
  }
}
/************************************************************************************************
Function:	  WriteGraphicScreen
Description: write a graphic to screen 
Calls:			- LCD_WriteChar
Input:			- U8 lines(graphic data matrix lines),
              U8 column_bytes(graphic bytes each line),
              U8 line_addr(display starting address line(0~64)),
              U8 column_addr(0~7),
              U8 *GDData(64*16*8 dots,64*16 = 1024bytes)
Output:			- graphic diplay
Return:			- None
**************************************************************************************************/
void WriteGraphicScreen(U8 lines,U8 column_bytes,U8 line_addr,U8 column_addr,U8 *GDData)
{
	U8 TempData;
	U8 i, j;
	U8 addr_x,addr_y;
    for(i=line_addr;i<lines+line_addr;i++)    //
   {
    //set address
     if(i<32){
       addr_y = 0x80+i;
       addr_x = 0x80+column_addr;
      
     } 
     else {
       addr_y = 0x80+(i - 32);
       addr_x = 0x80+column_addr+0x08;
     }
      LCD_WriteChar(0,0x34);// 8bit I/F, extend command      
    	LCD_WriteChar(0,addr_y);// Y address
    	LCD_WriteChar(0,addr_x);  // X address  
      LCD_WriteChar(0,0x30);  // 8bit I/F, basic command,// graphic on
                 
      	for(j=0;j<column_bytes/2;j++)         //10
     		{
     		TempData=(*(GDData+((i-line_addr)*column_bytes)+(j*2)+0)); // send high-byte
     		LCD_WriteChar(1,TempData);
     	//	 delay_Nms(1);      ////////////////////////////a must
     		TempData=(*(GDData+((i-line_addr)*column_bytes)+(j*2)+1)); // send low-byte
     		LCD_WriteChar(1,TempData);     	
     	//	 delay_Nms(1);      ////////////////////////////a must	
 		    }      
    }
    LCD_WriteChar(0,0x36);  // 8bit I/F, basic command graphic on
}
/************************************************************************************************
Function:	  TeamInfor
Description: TeamInfor
Calls:			- LCD_WriteChar,LCD_write_string ,delay_Nms ,WriteGraphicScreen ,ShowMenu
Input:			- None
Output:			- None
Return:			- None
**************************************************************************************************/
void TeamInfor(void){
 //
  LCD_Init();
  delay_Nms(10);
  ScreenClean();
  delay_Nms(10);      ////////////////////////////a must
  WriteGraphicScreen(64,8,0,0,glogo_szu);
  //
  LCD_WriteChar(0,0x30);  // 8bit I/F, basic command, graphic off
  LCD_WriteChar(0,0x0c);  // display on
  LCD_write_string(0,4,"深圳大学");
  LCD_write_string(1,4,"信息工程");
  LCD_write_string(2,4,"荔园晨风");
  //
  WaitForKey();
  //
  LCD_WriteChar(0,0x30);  // 8bit I/F, basic command, graphic off
  LCD_WriteChar(0,0x0c);  // display on
  LCD_WriteChar(0,0x01);  // clr text screen
  LCD_write_string(0,0,"指导老师: 钱恭斌");
  LCD_write_string(1,0,"参赛队员: 周东泳");
  LCD_write_string(2,0,"          张战斌");
  LCD_write_string(3,0,"          李真棠");
  WaitForKey();
  LCD_WriteChar(0,0x01);  // clr text screen
  ShowMenu(); 

}
/************************************************************************************************
Function:	  LCD_Init
Description: LCD initial
Calls:			- LCD_WriteChar, clrReg8Bits ,delay_Nms
Input:			- None
Output:			- None
Return:			- None
**************************************************************************************************/
void LCD_Init(void)
{
    //initial port regesiter
    LCD_DATA = 0x00;
    LCD_DATA_OUT;  //port data regesiter out put
    clrReg8Bits(PEAR, 140);               
    clrReg8Bits(PORTE,140); //io data set 0             
    setReg8Bits(PUCR, 145); //regester pull up               
    setReg8Bits(DDRE, 140); //command out              
    //initial signals
    LCD_SCLK_CLR;             
    LCD_SID_CLR;
    LCD_CS_CLR;
    delay_Nms(1);
    //commands
    //ScreenClean();
    //
    LCD_WriteChar(0,0x30);  // 8bit I/F, basic command, graphic off
    delay_Nms(1);      ////////////////////////////a must
    LCD_WriteChar(0,0x0c);  // display on
    delay_Nms(1);      ////////////////////////////a must
    LCD_WriteChar(0,0x06);  // cursor right shift
    delay_Nms(1);      ////////////////////////////a must
    LCD_WriteChar(0,0x01);  // clr text screen
    delay_Nms(1);      ////////////////////////////a must
    
}


⌨️ 快捷键说明

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