Exemplo n.º 1
0
/*******************************************************************************
* Function Name  : LCD_WriteRAM_Prepare
* Description    : Prepare to write to the LCD RAM.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_WriteRAM_Prepare(void)
{
    LCD_WriteRegIndex(R34); /* Select GRAM Reg */

    /* Reset LCD control line(/CS) and Send Start-Byte */
    LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
}
Exemplo n.º 2
0
/*******************************************************************************
* Function Name  : LCD_ReadReg
* Description    : Reads the selected LCD Register.
* Input          : None
* Output         : None
* Return         : LCD Register Value.
*******************************************************************************/
u16 LCD_ReadReg(u8 LCD_Reg)
{
    vu16 tmp = 0;
    vu8 i = 0;

    /* SPI3 prescaler: 4 */
    SPI3->CR1 &= 0xFFC7;
    SPI3->CR1 |= 0x0008;

    /* Write 16-bit Index (then Read Reg) */
    LCD_WriteRegIndex(LCD_Reg);

    /* Read 16-bit Reg */
    /* Reset LCD control line(/CS) and Send Start-Byte */
    LCD_nCS_StartByte(START_BYTE | LCD_READ_REG);

    for(i = 0; i < 5; i++) {
        SPI_I2S_SendData(SPI3, 0xFF);

        while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET) {
            vBlockToWait( 1 );
        }
        /* One byte of invalid dummy data read after the start byte */
        while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE) == RESET) {
            vBlockToWait( 1 );
        }
        SPI_I2S_ReceiveData(SPI3);
    }

    SPI_I2S_SendData(SPI3, 0xFF);
    /* Read upper byte */
    while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET) {
        vBlockToWait( 1 );
    }
    /* Read lower byte */
    while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE) == RESET) {
        vBlockToWait( 1 );
    }
    tmp = SPI_I2S_ReceiveData(SPI3);


    SPI_I2S_SendData(SPI3, 0xFF);
    while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET) {
        vBlockToWait( 1 );
    }
    /* Read lower byte */
    while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE) == RESET) {
        vBlockToWait( 1 );
    }
    tmp = ((tmp & 0xFF) << 8) | SPI_I2S_ReceiveData(SPI3);

    LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);

    /* SPI3 prescaler: 2 */
    SPI3->CR1 &= 0xFFC7;

    return tmp;
}
/**
  * @brief  Reads the selected LCD Register.
  * @param  None
  * @retval LCD Register Value.
  */
uint16_t LCD_ReadReg(uint8_t LCD_Reg)
{
  uint16_t tmp = 0;
  uint8_t i = 0;
  
  /* LCD_SPI prescaler: 4 */
  LCD_SPI->CR1 &= 0xFFC7;
  LCD_SPI->CR1 |= 0x0008;
  /* Write 16-bit Index (then Read Reg) */
  LCD_WriteRegIndex(LCD_Reg);
  /* Read 16-bit Reg */
  /* Reset LCD control line(/CS) and Send Start-Byte */
  LCD_nCS_StartByte(START_BYTE | LCD_READ_REG);
  
  for(i = 0; i < 5; i++)
  {
    SPI_I2S_SendData(LCD_SPI, 0xFF);
    while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
    {
    }
    /* One byte of invalid dummy data read after the start byte */
    while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
    {    
    }
    SPI_I2S_ReceiveData(LCD_SPI); 
  }
  SPI_I2S_SendData(LCD_SPI, 0xFF);
  /* Read upper byte */
  while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
  {
  }
  /* Read lower byte */
  while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
  {
  }
  tmp = SPI_I2S_ReceiveData(LCD_SPI);
  
  
  SPI_I2S_SendData(LCD_SPI, 0xFF);
  while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET)
  {
  }
  /* Read lower byte */
  while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_RXNE) == RESET)
  {
  }
  tmp = ((tmp & 0xFF) << 8) | SPI_I2S_ReceiveData(LCD_SPI);
  LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
  /* LCD_SPI prescaler: 2 */
  LCD_SPI->CR1 &= 0xFFC7;
  return tmp;
}
Exemplo n.º 4
0
/**
  * @brief  Writes index to select the LCD register.
  * @param  LCD_Reg: address of the selected register.
  * @retval None
  */
void LCD_WriteRegIndex(uint8_t LCD_Reg)
{
	/* Reset LCD control line(/CS) and Send Start-Byte */
	LCD_nCS_StartByte(START_BYTE | SET_INDEX);
	/* Write 16-bit Reg Index (High Byte is 0) */
	SPI_I2S_SendData(LCD_SPI, 0x00);
	while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET) {
	}
	SPI_I2S_SendData(LCD_SPI, LCD_Reg);
	while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET) {
	}
	LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
}
Exemplo n.º 5
0
/**
  * @brief  Writes to the selected LCD register.
  * @param  LCD_Reg: address of the selected register.
  * @param  LCD_RegValue: value to write to the selected register.
  * @retval None
  */
void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
{
	/* Write 16-bit Index (then Write Reg) */
	LCD_WriteRegIndex(LCD_Reg);
	/* Write 16-bit Reg */
	/* Reset LCD control line(/CS) and Send Start-Byte */
	LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
	SPI_I2S_SendData(LCD_SPI, LCD_RegValue>>8);
	while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET) {
	}
	SPI_I2S_SendData(LCD_SPI, (LCD_RegValue & 0xFF));
	while(SPI_I2S_GetFlagStatus(LCD_SPI, SPI_I2S_FLAG_BSY) != RESET) {
	}
	LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
}
Exemplo n.º 6
0
/*******************************************************************************
* Function Name  : LCD_WriteRegIndex
* Description    : Writes index to select the LCD register.
* Input          : - LCD_Reg: address of the selected register.
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_WriteRegIndex(u8 LCD_Reg)
{
    /* Reset LCD control line(/CS) and Send Start-Byte */
    LCD_nCS_StartByte(START_BYTE | SET_INDEX);

    /* Write 16-bit Reg Index (High Byte is 0) */
    SPI_I2S_SendData(SPI3, 0x00);
    while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET) {
        vBlockToWait( 1 );
    }
    SPI_I2S_SendData(SPI3, LCD_Reg);
    while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET) {
        vBlockToWait( 1 );
    }

    LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
}
Exemplo n.º 7
0
/*******************************************************************************
* Function Name  : LCD_WriteReg
* Description    : Writes to the selected LCD register.
* Input          : - LCD_Reg: address of the selected register.
*                  - LCD_RegValue: value to write to the selected register.
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_WriteReg(u8 LCD_Reg, u16 LCD_RegValue)
{
    /* Write 16-bit Index (then Write Reg) */
    LCD_WriteRegIndex(LCD_Reg);

    /* Write 16-bit Reg */
    /* Reset LCD control line(/CS) and Send Start-Byte */
    LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);

    SPI_I2S_SendData(SPI3, LCD_RegValue>>8);
    while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET) {
        vBlockToWait( 1 );
    }
    SPI_I2S_SendData(SPI3, (LCD_RegValue & 0xFF));
    while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET) {
        vBlockToWait( 1 );
    }

    LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
}