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

📄 ks0108_12864lcd.c

📁 ks0108 avr单片机1284显示
💻 C
📖 第 1 页 / 共 2 页
字号:
      LCD_INSTR_PORT |=  LCD_DI; // Set data   
   else
      LCD_INSTR_PORT &= ~LCD_DI; // Set instruction

   LCD_INSTR_PORT &= ~LCD_RW; // Set write
   
   if (IVERSE && DATA_FLAG)   
      LCD_DATA_PORT = 255 - DATA; // Send inverse data
   else
      LCD_DATA_PORT = DATA; // Send data or instruction
   
   LCD_INSTR_PORT &= ~LCD_EN; // Toggle enable
   asm("nop");	
   asm("nop");
   }

/*----------------------------------------------------------------------------*-
  
   LCD_Set_XY()

   Set the DDRAM to a particular address.

   Used to determine where we write to in the LCD RAM and - thus -
   whether the text appears on Page 0, page 1, Column 0, Column 1, etc.

   Params (X, Y) : The DDRAM address we wish to write to. 
   
   X range : (Page 0 ~ Page 7), Y range : (0 ~ 127)

-*----------------------------------------------------------------------------*/
static void LCD_Set_XY(uInt8 X, uInt8 Y)
   {
   if (Y >= 64)
      {
      LCD_INSTR_PORT &= ~LCD_CS1; // Select right side
      LCD_INSTR_PORT |=  LCD_CS2;
      LCD_Send_Byte((DISPLAY_PAGE_SET + X), COMMAND, NORMAL); // Set page 
      LCD_Send_Byte((DISPLAY_COLUMN_SET + Y - 64), COMMAND, NORMAL); // Set column
	  }
   else
      {
      LCD_INSTR_PORT |=  LCD_CS1; // Select left side
      LCD_INSTR_PORT &= ~LCD_CS2;
	  LCD_Send_Byte((DISPLAY_PAGE_SET + X), COMMAND, NORMAL); // Set page 
      LCD_Send_Byte((DISPLAY_COLUMN_SET + Y), COMMAND, NORMAL); // Set column
	  }	  	  
   }
  
/*----------------------------------------------------------------------------*-

   LCD_Disp_a_Char()    
 
   Used to determine where we want to dispaly a char on the LCD panel 
   and - thus - whether the text appears on Page 0, page 1, Column 0, 
   Column 1, etc.

   Parameters:  
   ---------------------------------------------------------------------------
   X : range (Page 0 ~ Page 7)    
   Y : range (0 ~ 127)
   Params (X, Y) : The DDRAM address we wish to write to.

   Char_Value : The character value which's going to be displayed 
                on the LCD panel 
			   
   Video_Mode : If Video_Mode == INVERSE(1), inverse video mode			   
                If Video_Mode == NORMAL(0), normal video mode
			   
-*----------------------------------------------------------------------------*/
static void LCD_Disp_a_Char(uInt8 X, uInt8 Y, uInt8 Char_Value, 
                            uInt8 Video_Mode)
   {
   uInt8 cl;
   
   // Fine the char in the lookup table
   // See "FONT6x8.C" for details
   Char_Value -= 32;
     
   for (cl = 0; cl < 6; cl++)
      {
	  LCD_Set_XY(X, Y + cl);
      LCD_Send_Byte(FONT6x8[Char_Value][cl], D_DATA, Video_Mode);
	  }
   }

/*----------------------------------------------------------------------------*-
   
   LCD_Disp_String()

   Used to determine where we want to dispaly a string on the LCD panel 
   and - thus - whether the text appears on Page 0, page 1, Column 0, 
   Column 1, etc.

   Parameters: 
   ---------------------------------------------------------------------------
   X : range (Page 0 ~ Page 7)    
   Y : range (0 ~ 127)
   Params (X, Y) : The DDRAM address we wish to write to.

   pString    : The string pointer point out the string which's going to 
                be displayed on the LCD panel

   Video_Mode : If Video_Mode == INVERSE(1), inverse video mode			   
                If Video_Mode == NORMAL(0), normal video mode
				   		
-*----------------------------------------------------------------------------*/
static void LCD_Disp_String(uInt8 X, uInt8 Y, flash uInt8 * pString, 
                            uInt8 Video_Mode)
   {
   while (* pString) 
      {
      LCD_Disp_a_Char(X, Y, * pString, Video_Mode);
	  Y += 6; // Characters are 6x8 pixel
	  pString++;	  
      }
   }   

/*----------------------------------------------------------------------------*-

   LCD_Disp_Chinese_String()
  
   Display a Chinese String on the LCD panel.
  
   Parameters: 
   ---------------------------------------------------------------------------
   X, Y        : The Chinese String start coordinates on the LCD panel
    
   Char_Length : The Chinese character's length (in pixel)
   Char_Amount : The amount of Chinese characters 
   Start_Char  : Which Chinese character should be display first in the array
   Char_Gap    : The space between on characters to another (in pixel)
   
   Video_Mode  : If Video_Mode == INVERSE(1), inverse video mode			   
                 If Video_Mode == NORMAL(0), normal video mode
	
-*----------------------------------------------------------------------------*/                        
static void LCD_Disp_Chinese_String (uInt8 X, uInt8 Y, 
                                     uInt8 Char_Length, uInt8 Char_Amount,
                                     uInt8 Start_Char, uInt8 Char_Gap,
									 flash uInt8 (* pCN_String)[32], 
									 uInt8 Video_Mode)
   {
   uInt8 cl, nm; 
    
   for (nm = 0; nm < Char_Amount; )
      {
      for (cl = 0; cl < Char_Length * 2; cl++) // Send a Chinese character
         { 
      	 if (cl >= Char_Length)  
            { 
			// Send below part of a Chinese character
			LCD_Set_XY(X + 1, Y + cl - Char_Length);
			}
         else
		    {
		    // Set coordinates    
            LCD_Set_XY(X, Y + cl);
			}
 
      	 LCD_Send_Byte(* (* (pCN_String + Start_Char + nm)+ cl), 
		                     D_DATA, Video_Mode);
         }      
	  Y = Y + Char_Length + Char_Gap;
	  nm++;
      }
   }

/*----------------------------------------------------------------------------*-

   LCD_Disp_an_Image() 

   Display an Image on the LCD panel.

   Parameters: 
   ---------------------------------------------------------------------------
   X, Y             : The Image start coordinates on the LCD panel
    
   pImage           : Image data pointer (Image stored in Flash area)

   pixel_X, pixel_Y : The Image's size
   
                      Pixel_X, the height of the Image (in pixel)
					  Pixel_Y, the length of the Image (in pixel)
					  
   Video_Mode : If Video_Mode == INVERSE(1), inverse video mode			   
                If Video_Mode == NORMAL(0), normal video mode

-*----------------------------------------------------------------------------*/
static void LCD_Disp_an_Image(uInt8 X, uInt8 Y, flash uInt8 * pImage,
                              uInt8 Pixel_X, uInt8 Pixel_Y, uInt8 Video_Mode)
   {   
   uInt8 cl, pg;
   uInt8 Page;
   
   // Figure out needs how many Pages
   // to display the Image  
   if (Pixel_X % 8 == 0) 
      Page = Pixel_X / 8;   
   else
      Page = Pixel_X / 8 + 1;  
      
   // Now send the Image
   for (pg = 0; pg < Page; pg++)
      {  
	  // Send Image data
      for(cl = 0; cl < Pixel_Y; cl++)
         {
		 // Set coordinates
         LCD_Set_XY(X + pg, Y + cl);
		 	 
         LCD_Send_Byte(pImage[cl + Pixel_Y * pg], D_DATA, Video_Mode);
         }                       
      }      
   }
   
/*----------------------------------------------------------------------------*-

   LCD_Draw_a_Dot() 

   Draw a dot (one pixel) on specific location of the LCD panel.

   Parameters: 
   ---------------------------------------------------------------------------
   X, Y             : The dot location on the LCD panel
   
   X range : (0 ~ 63), Y range : (0 ~ 127) 

-*----------------------------------------------------------------------------*/
static void LCD_Draw_a_Dot(uInt8 X, uInt8 Y, uInt8 Video_Mode)
   {   
   uInt8 Page, Which_Bit_Should_be_Lit;
   
   // Figure out which Page the dot locate  
   Page = X / 8;
   
   // Find which bit of the data should be lit up
   Which_Bit_Should_be_Lit = (1 << (X % 8)); 
   
   LCD_Set_XY(Page, Y);
 
   LCD_DATA_PORT = 0xFF;  
   LCD_DATA_PORT_DIR = INPUT; // Set data PORT direction

   LCD_INSTR_PORT |=  LCD_DI; // Set data
   LCD_INSTR_PORT |=  LCD_RW; // Set read
   
   LCD_INSTR_PORT |=  LCD_EN;
   asm("nop");	
   asm("nop");
    
   LCD_INSTR_PORT &= ~LCD_EN; // Toggle enable
   asm("nop");	
   asm("nop");
    
   if (Video_Mode) // Clear a dot on the panel
      Which_Bit_Should_be_Lit = (~Which_Bit_Should_be_Lit & LCD_DATA_PORT_VL);
	  
   else            // Set a dot on the panel
      Which_Bit_Should_be_Lit = (Which_Bit_Should_be_Lit | LCD_DATA_PORT_VL); 
  
   LCD_DATA_PORT_DIR = OUTPUT; // Set data PORT direction back to an output
   LCD_INSTR_PORT &= ~LCD_EN;
   
   LCD_Set_XY(Page, Y);
   LCD_Send_Byte(Which_Bit_Should_be_Lit, D_DATA, NORMAL);     
   }

/*----------------------------------------------------------------------------*-
  ---- END OF FILE -----------------------------------------------------------
-*----------------------------------------------------------------------------*/

⌨️ 快捷键说明

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