STM32F10X系列LCD屏的配置及子函数


       首先是LCD的RAM写子函数:

void LCD_WriteRAM(u16 RGB_Code)
{
  GPIO_SetBits(LCD_RS_PORT,LCD_RS_PIN);   
  
  GPIO_Write(LCD_PORT_PORT,RGB_Code>>8);
  //Delay(5);		
  GPIO_ResetBits(LCD_WR_PORT,LCD_WR_PIN); 
  //Delay(10);
  GPIO_SetBits(LCD_WR_PORT,LCD_WR_PIN);

  GPIO_Write(LCD_PORT_PORT,RGB_Code);
 // Delay(10);		
  GPIO_ResetBits(LCD_WR_PORT,LCD_WR_PIN); 
  //Delay(10);
  GPIO_SetBits(LCD_WR_PORT,LCD_WR_PIN);
}

     LCD从RAM读取字符并进行显示的子函数:

void LCD_DrawChar(u8 Xpos, u16 Ypos, const u16 *c)
{
  u32 index = 0, i = 0;
  u8 Xaddress = 0;
   
  Xaddress = Xpos;
  
  LCD_SetCursor(Xaddress, 319-Ypos);
  
  for(index = 0; index < 24; index++)
  {
    LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
    for(i = 0; i < 16; i++)
    {
      if((c[index] & (1 << i)) == 0x00)
      {
        LCD_WriteRAM(BackColor);
      }
      else
      {
        LCD_WriteRAM(TextColor);
      }
    }   
    LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); 
    Xaddress++;
    LCD_SetCursor(Xaddress, 319-Ypos);
  }
}


       ASCII码转换的基本
void LCD_DisplayChar(u8 Line, u16 Column, u8 Ascii)
{
  Ascii -= 32;
  LCD_DrawChar(Line, Column, &ASCII_Table[Ascii * 24]);
}



       可以应用于主函数的数字显示函数:

void LCD_ShowNum(uint8_t x,uint16_t y,uint16_t data)
{
LCD_DisplayChar(x,y,data/10000+48); 
LCD_DisplayChar(x,(y+25),data%10000/1000+48);   // %10000
LCD_DisplayChar(x,(y+50),data%1000/100+48); 
LCD_DisplayChar(x,(y+75),data%100/10+48);	 
LCD_DisplayChar(x,(y+100),data%10+48);
}	

      可以用于主函数的字符显示函数:

void LCD_DisplayStringLine(u8 Line, u8 *ptr)
{
  u32 i = 0;
  u16 refcolumn =0;
  /* Send the string character by character on lCD */
  while ((*ptr != 0) & (i < 20))
  {
    /* Display one character on LCD */
    LCD_DisplayChar(Line*FONT_HEIGHT, refcolumn, *ptr);
    /* Decrement the column position by 16 */
    refcolumn += FONT_WIDTH;
    /* Point on the next character */
    ptr++;
    /* Increment the character counter */
    i++;
  }
}



你可能感兴趣的:(STM32开发,C,单板开发)