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

📄 glcd.c

📁 STM32驱动ADXL345
💻 C
📖 第 1 页 / 共 2 页
字号:
	  wr_reg(0x07, 0x0173);                 /* 262K color and display ON          */
  	}
	else if(DriverCode == 0x7783)
	{
	  // Start Initial Sequence
	  	wr_reg(0x00FF,0x0001);
	  	wr_reg(0x00F3,0x0008);
		wr_reg(0x0001,0x0100);
		wr_reg(0x0002,0x0700);
		wr_reg(0x0003,0x1030);  //0x1030
		wr_reg(0x0008,0x0302);
		wr_reg(0x0008,0x0207);
		// Power On sequence 
		wr_reg(0x0009,0x0000);
		wr_reg(0x000A,0x0000);
		wr_reg(0x0010,0x0000);  //0x0790
		wr_reg(0x0011,0x0005);
		wr_reg(0x0012,0x0000);
		wr_reg(0x0013,0x0000);
		delay(5);
		wr_reg(0x0010,0x12B0);
		delay(5);
		wr_reg(0x0011,0x0007);
		delay(5);
		wr_reg(0x0012,0x008B);
		delay(5);
		wr_reg(0x0013,0x1700);
		delay(5);
		wr_reg(0x0029,0x0022);
		
		// void Gamma_Set(void) 
		wr_reg(0x0030,0x0000);
		wr_reg(0x0031,0x0707);
		wr_reg(0x0032,0x0505);
		wr_reg(0x0035,0x0107);
		wr_reg(0x0036,0x0008);
		wr_reg(0x0037,0x0000);
		wr_reg(0x0038,0x0202);
		wr_reg(0x0039,0x0106);
		wr_reg(0x003C,0x0202);
		wr_reg(0x003D,0x0408);
		delay(5);
		
		// Set GRAM area
		wr_reg(0x0050,0x0000);		
		wr_reg(0x0051,0x00EF);		
		wr_reg(0x0052,0x0000);		
		wr_reg(0x0053,0x013F);		
		wr_reg(0x0060,0xA700);		
		wr_reg(0x0061,0x0001);
		wr_reg(0x0090,0x0033);				
		wr_reg(0x002B,0x000B);
		
		/* Set GRAM write direction and BGR = 1
	     I/D=10 (Horizontal : increment, Vertical : increment)
	     AM=1 (address is updated in vertical writing direction)                  */
	    wr_reg(0x03, 0x1038);		
		wr_reg(0x0007,0x0133);
	}
}


void GLCD_putPixel(unsigned int x, unsigned int y) {
  wr_reg(0x20, x);
  wr_reg(0x21, y);
  wr_reg(0x22,TextColor);
}


/*******************************************************************************
* Set foreground color                                                         *
*   Parameter:    color:  color for clearing display                           *
*   Return:                                                                    *
*******************************************************************************/
void GLCD_setTextColor(unsigned short color) {
  TextColor = color;
}


/*******************************************************************************
* Set background color                                                         *
*   Parameter:    color:  color for clearing display                           *
*   Return:                                                                    *
*******************************************************************************/
void GLCD_setBackColor(unsigned short color) {
  BackColor = color;
}


/*******************************************************************************
* Clear display                                                                *
*   Parameter:    color:  color for clearing display                           *
*   Return:                                                                    *
*******************************************************************************/

void GLCD_clear (unsigned short color) {
  unsigned int   i;

  wr_reg(0x20, 0);
  wr_reg(0x21, 0);
  Clr_Cs;
  wr_cmd(0x22);
  for(i = 0; i < (WIDTH*HEIGHT); i++)
  {
  	wr_dat(color);
  }
  Set_Cs;  
}


/*******************************************************************************
* Draw character on given position (line, coloum                               *
*   Parameter:     x :        horizontal position                              *
*                  y :        vertical position                                *
*                  c*:        pointer to color value                           *
*   Return:                                                                    *
*******************************************************************************/
void GLCD_drawChar(unsigned int x, unsigned int y, unsigned short *c) {
  unsigned int index = 0;
  int  i = 0;
  unsigned int Xaddress = 0;
   
  Xaddress = x;
  
  wr_reg(0x20, Xaddress);
  wr_reg(0x21, y);

  for(index = 0; index < 24; index++)
  {
  	Clr_Cs;
    wr_cmd(0x22);              /* Prepare to write GRAM */
    for(i = 15; i >= 0; i--)
//    for(i = 0; i < 16; i++)
    {
      if((c[index] & (1 << i)) == 0x00) {
        wr_dat(BackColor);
      } else {
        wr_dat(TextColor);
      }
    }
	Set_Cs;
    Xaddress++;
    wr_reg(0x20, Xaddress);
    wr_reg(0x21, y);
  }
}


/*******************************************************************************
* Disply character on given line                                               *
*   Parameter:     c :        ascii character                                  *
*                  ln:        line number                                      *
*   Return:                                                                    *
*******************************************************************************/
void GLCD_displayChar(unsigned int ln, unsigned int col, unsigned char  c) {
  c -= 32;
  GLCD_drawChar(ln, col, &ASCII_Table[c * 24]);
}


/*******************************************************************************
* Disply string on given line                                                  *
*   Parameter:     s*:        pointer to string                                *
*                  ln:        line number                                      *
*   Return:                                                                    *
*******************************************************************************/
void GLCD_displayStringLn(unsigned int ln, unsigned char *s) {
  unsigned int i = 0;
  unsigned int refcolumn = (WIDTH/*-1*/)-16;

  while ((*s != 0) & (i < 20))                   /* write the string character by character on lCD */
  {
    GLCD_displayChar(ln, refcolumn, *s);         /* Display one character on LCD */
    refcolumn -= 16;                             /* Decrement the column position by 16 */
    s++;                                         /* Point on the next character */
    i++;                                         /* Increment the character counter */
  }
}


/*******************************************************************************
* Clear given line                                                             *
*   Parameter:     ln:        line number                                      *
*   Return:                                                                    *
*******************************************************************************/
void GLCD_clearLn(unsigned int ln) {
  GLCD_displayStringLn(ln, "                    ");
}


/*******************************************************************************
* Display graphical bitmap image at position x horizontally and y vertically   *
* (This function is optimized for 16 bits per pixel format, it has to be       *
*  adapted for any other bits per pixel format)                                *
*   Parameter:      x:        horizontal position                              *
*                   y:        vertical position                                *
*                   w:        width of bitmap                                  *
*                   h:        height of bitmap                                 *
*                   bitmap:   address at which the bitmap data resides         *
*   Return:                                                                    *
*******************************************************************************/

void GLCD_bitmap (unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bitmap) {
  unsigned int   i;
  unsigned int   len = w*h;
  unsigned short *bitmap_ptr = (unsigned short *)bitmap;

  wr_reg(0x50, y);                      /* Horizontal GRAM Start Address      */
  wr_reg(0x51, y+h-1);                  /* Horizontal GRAM End   Address (-1) */
  wr_reg(0x52, x);                      /* Vertical   GRAM Start Address      */
  wr_reg(0x53, x+w-1);                  /* Vertical   GRAM End   Address (-1) */

  wr_reg(0x20, y);
  wr_reg(0x21, x);

  Clr_Cs;
  wr_cmd(0x22);
  for (i = 0; i < len; i++) {
    wr_dat(*bitmap_ptr++);
  }
  Set_Cs;
}

/****************************************************************************
* 名    称:void GLCD_Test(void)
* 功    能:测试液晶屏
* 入口参数:无
* 出口参数:无
* 说    明:显示彩条,测试液晶屏是否正常工作
* 调用方法:GLCD_Test();
****************************************************************************/
void GLCD_Test(void)
{
  u16 i,j;
  wr_reg(0x20, 0);
  wr_reg(0x21, 0);

  Clr_Cs; 
  wr_cmd(0x22);
  
  for(i=0;i<320;i++)
    for(j=0;j<240;j++)
    {
      if(i>279)wr_dat(0x0000);
      else if(i>239)wr_dat(0x001f);
      else if(i>199)wr_dat(0x07e0);
      else if(i>159)wr_dat(0x07ff);
      else if(i>119)wr_dat(0xf800);
      else if(i>79)wr_dat(0xf81f);
      else if(i>39)wr_dat(0xffe0);
      else wr_dat(0xffff);
    }
  Set_Cs;
}


/******************************************************************************/

⌨️ 快捷键说明

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