这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » STM32 » wambob的 ST L053进程贴(点亮液晶屏)

共3条 1/1 1 跳转至

wambob的 ST L053进程贴(点亮液晶屏)

高工
2015-12-17 18:19:55     打赏

液晶显示屏在人机界面中,有着重要的地位,因为大部分信息由人的视觉系统处理。

此液晶的主控器为ss1289SSD1289控制器资料.pdf

其中寄存器  R25h帧频率控制  我在文档中怎么也找不到

准备软件 cubeMX和库stm32cubel0_1.30.zip

下面使用cubeMX建立工程

完成库的安装

新工程

配置好管脚

配置时钟

工程设置

产生工程代码

初始化管脚后的工程框架就完成了,液晶屏显示相关代码就要靠自己了

/**
  ******************************************************************************
  * File Name          : main.c
  * Description        : Main program body
  ******************************************************************************
  *
  * COPYRIGHT(c) 2015 STMicroelectronics
  *
  * Redistribution and use in source and binary forms, with or without modification,
  * are permitted provided that the following conditions are met:
  *   1. Redistributions of source code must retain the above copyright notice,
  *      this list of conditions and the following disclaimer.
  *   2. Redistributions in binary form must reproduce the above copyright notice,
  *      this list of conditions and the following disclaimer in the documentation
  *      and/or other materials provided with the distribution.
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "stm32l0xx_hal.h"

/* USER CODE BEGIN Includes */
#include "pic3.h"
/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
//PB0---PB7 低8位 PB8---PB15 高8位 PC6---RD PC7---WR PC8---RS PC9---CS PC5 =RESET
#define Set_Cs  HAL_GPIO_WritePin( GPIOC, GPIO_PIN_9, GPIO_PIN_SET);
#define Clr_Cs  HAL_GPIO_WritePin( GPIOC, GPIO_PIN_9, GPIO_PIN_RESET);        

#define Set_Rs  HAL_GPIO_WritePin( GPIOC, GPIO_PIN_8, GPIO_PIN_SET);
#define Clr_Rs  HAL_GPIO_WritePin( GPIOC, GPIO_PIN_8, GPIO_PIN_RESET);

#define Set_nWr HAL_GPIO_WritePin( GPIOC, GPIO_PIN_7, GPIO_PIN_SET);
#define Clr_nWr HAL_GPIO_WritePin( GPIOC, GPIO_PIN_7, GPIO_PIN_RESET);

#define Set_nRd HAL_GPIO_WritePin( GPIOC, GPIO_PIN_6, GPIO_PIN_SET);
#define Clr_nRd HAL_GPIO_WritePin( GPIOC, GPIO_PIN_6, GPIO_PIN_RESET);

#define Set_RESET HAL_GPIO_WritePin( GPIOC, GPIO_PIN_5, GPIO_PIN_SET);
#define Clr_RESET HAL_GPIO_WritePin( GPIOC, GPIO_PIN_5, GPIO_PIN_RESET);

#define     RED          0XF800	  
#define     GREEN        0X07E0	  
#define     BLUE         0X001F	  
#define     WHITE        0XFFFF	  
#define     BLACK        0X0000	  
#define     YELLOW       0XFFE0	  
#define     ORANGE       0XFC08	  
#define     GRAY  	     0X8430   
#define     LGRAY        0XC618	  
#define     DARKGRAY     0X8410	  
#define     PORPO        0X801F	  
#define     PINK         0XF81F
#define     GRAYBLUE     0X5458   
#define     LGRAYBLUE    0XA651   
#define     DARKBLUE     0X01CF	  
#define 	LIGHTBLUE    0X7D7C	 
	    															  
#define Line0                0
#define Line1               24
#define Line2               48
#define Line3               72
#define Line4               96
#define Line5              120
#define Line6              144
#define Line7              168
#define Line8              192
#define Line9              216
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);

/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
void Lcd_Write_Com( int  DH);
void Lcd_Write_DATA(int DH);
void Lcd_Init(void);
void Lcd_Write_Com_Data( unsigned int com1,unsigned int dat1);
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2);
//void Pant(uint32_t color);
void Pant();
/* USER CODE END PFP */

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

int main(void)
{
  /* USER CODE BEGIN 1 */
  
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();

  /* USER CODE BEGIN 2 */
Lcd_Init();


  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
// Lcd_Init();   
//	Pant(0xf800); //红色
//	HAL_Delay(1000);
//	Pant(0X07E0); //绿色
//	HAL_Delay(1000);
//	Pant(0x001f); //蓝色 
//	HAL_Delay(1000);
    Pant();
    	

	
  }
  /* USER CODE END 3 */

}

/** System Clock Configuration
*/
void SystemClock_Config(void)
{

  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  __PWR_CLK_ENABLE();

  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = 16;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_4;
  RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2;
  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1);

  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  /* SysTick_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

/** Configure pins as 
        * Analog 
        * Input 
        * Output
        * EVENT_OUT
        * EXTI
     PA2   ------> USART2_TX
     PA3   ------> USART2_RX
*/
void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */
  __GPIOC_CLK_ENABLE();
  __GPIOH_CLK_ENABLE();
  __GPIOA_CLK_ENABLE();
  __GPIOB_CLK_ENABLE();

  /*Configure GPIO pin : B1_Pin */
  GPIO_InitStruct.Pin = B1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : USART_TX_Pin USART_RX_Pin */
  GPIO_InitStruct.Pin = USART_TX_Pin|USART_RX_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  GPIO_InitStruct.Alternate = GPIO_AF4_USART2;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pin : LD2_Pin */
  GPIO_InitStruct.Pin = LD2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : PC5 PC6 PC7 PC8 
                           PC9 */
  GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8 
                          |GPIO_PIN_9;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /*Configure GPIO pins : PB0 PB1 PB2 PB10 
                           PB11 PB12 PB13 PB14 
                           PB15 PB3 PB4 PB5 
                           PB6 PB7 PB8 PB9 */
  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_10 
                          |GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14 
                          |GPIO_PIN_15|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5 
                          |GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */
void Lcd_Write_Com( int  DH)	 //??
{	
    Clr_Rs ;
	Clr_Cs;	 
	GPIOB->ODR=DH;		
	Clr_nWr;
	Set_nWr;
	Set_Cs;	
}
void Lcd_Write_DATA(int DH)	//??	
{
    Set_Rs ;
	Clr_Cs;	  				
	GPIOB->ODR=DH;				
	Clr_nWr;
	Set_nWr;
	Clr_Cs;	
}


void Lcd_Write_Com_Data( unsigned int com1,unsigned int dat1)	
{
   Lcd_Write_Com(com1);
   Lcd_Write_DATA(dat1);
}



void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{ 
	Lcd_Write_Com_Data(0x0044,(x2<<8)+x1); //水平RAM地址位置
	Lcd_Write_Com_Data(0x0045,y1);     //垂直RAM开始位置
	Lcd_Write_Com_Data(0x0046,y2);    //垂直RAM结束位置
    Lcd_Write_Com_Data(0x004e,x1);   //设置X计数
	Lcd_Write_Com_Data(0x004f,y1);   //设置Y计数
    Lcd_Write_Com(0x0022);	     	  
   	
}	
void Lcd_Init(void)
{

    Set_RESET;
    HAL_Delay(5);	
	Clr_RESET;
	HAL_Delay(10);
	Set_RESET;
	Set_Cs;
	Set_nRd;
	Set_nWr;
	HAL_Delay(20);

    Lcd_Write_Com_Data(0x0000,0x0001);    HAL_Delay(1);  //打开晶振
    Lcd_Write_Com_Data(0x0003,0xA8A4);    HAL_Delay(1);   
    Lcd_Write_Com_Data(0x000C,0x0000);    HAL_Delay(1);   
    Lcd_Write_Com_Data(0x000D,0x080C);    HAL_Delay(1);   
    Lcd_Write_Com_Data(0x000E,0x2B00);    HAL_Delay(1);   
    Lcd_Write_Com_Data(0x001E,0x00B7);    HAL_Delay(1);   
    Lcd_Write_Com_Data(0x0001,0x2B3F);    HAL_Delay(1);   //驱动输出控制320*240  0x6B3F 293F 2B3F 6B3F 7A3F
    Lcd_Write_Com_Data(0x0002,0x0600);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0010,0x0000);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0011,0x6070);    HAL_Delay(1);        //0x4030           //??????  16?? 
    Lcd_Write_Com_Data(0x0005,0x0000);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0006,0x0000);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0016,0xEF1C);    HAL_Delay(1);   //设置每行有效像素的数目。每行有效像素数等于到XL[7:0]+1
    Lcd_Write_Com_Data(0x0017,0x0003);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0007,0x0233);    HAL_Delay(1);        //0x0233       
    Lcd_Write_Com_Data(0x000B,0x0000);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x000F,0x0000);    HAL_Delay(1);        //??????
    Lcd_Write_Com_Data(0x0041,0x0000);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0042,0x0000);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0048,0x0000);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0049,0x013F);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x004A,0x0000);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x004B,0x0000);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0044,0xEF00);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0045,0x0000);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0046,0x013F);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0030,0x0707);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0031,0x0204);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0032,0x0204);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0033,0x0502);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0034,0x0507);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0035,0x0204);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0036,0x0204);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0037,0x0502);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x003A,0x0302);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x003B,0x0302);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0023,0x0000);    HAL_Delay(1);
    Lcd_Write_Com_Data(0x0024,0x0000);    HAL_Delay(1);   
    Lcd_Write_Com_Data(0x004f,0);        //X计数0
    Lcd_Write_Com_Data(0x004e,0);        //Y计数0
	Lcd_Write_Com(0x0022);               //写到图像RAM
}

void Pant()
//void Pant(uint32_t color)
{
	uint32_t i,j;
	Address_set(0,0,239,319);
	
    for(i=0;i<320;i++)
	 {
	  for (j=0;j<240;j++)
	   	{
        
            if(i>279)Lcd_Write_DATA(0x0000);
                  else if(i>239)Lcd_Write_DATA(0x001f);
                  else if(i>199)Lcd_Write_DATA(0x07e0);
                  else if(i>159)Lcd_Write_DATA(0x07ff);
                  else if(i>119)Lcd_Write_DATA(0xf800);
                  else if(i>79)Lcd_Write_DATA(0xf81f);
                  else if(i>39)Lcd_Write_DATA(0xffe0);
                  else Lcd_Write_DATA(0xffff);

	    }

	  }		
}
void LCD_Picture(unsigned int xs,unsigned int ys,unsigned int xe,unsigned int ye)
{
	uint32_t temp;
	Address_set(xs,ys,xe,ye);	
	for(temp=0;temp<(xe-xs+1)*(ye-ys+1);temp++)
		Lcd_Write_DATA(((uint16_t)gImage_PIC3[2*temp]<<8)+gImage_PIC3[2*temp+1]);
}
void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos)
{	
		Lcd_Write_Com_Data(0X004E, Xpos);
		Lcd_Write_Com_Data(0X004F, Ypos);		
}
			
			
void LCD_SetWindow(uint16_t xs,uint16_t ys,uint16_t xe,uint16_t ye)
{
	
		if(xe > 239 || ye > 319) return;
		else					//竖屏
		{
		  	Lcd_Write_Com_Data(0x0044,xs+(xe<<8));
			Lcd_Write_Com_Data(0x0045,ys);
			Lcd_Write_Com_Data(0x0046,ye);
		}
	
}


/* USER CODE END 4 */

#ifdef USE_FULL_ASSERT

/**
   * @brief Reports the name of the source file and the source line number
   * where the assert_param error has occurred.
   * @param file: pointer to the source file name
   * @param line: assert_param error line source number
   * @retval None
   */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
    ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */

}

#endif

/**
  * @}
  */ 

/**
  * @}
*/ 

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

 



高工
2015-12-17 18:30:32     打赏
2楼

效果


菜鸟
2015-12-17 20:07:31     打赏
3楼
6666666666

共3条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]