void LcdInit(void) { //输出引脚初始化 Init_LCDGpio(); SpiInit(); //SPI初始化 LCD_SCLK_LOW(); LCD_SCLK_HIGH(); LCD_SDIN_LOW(); LCD_SDIN_HIGH(); LCD_DC_LOW(); LCD_DC_HIGH(); LCD_SCE_LOW(); LCD_SCE_HIGH(); LcdReset(); /*液晶复位*/ //LcdFunctionSet(ACTIVE, H_ADDR, EXT_INS); /*扩展指令集*/ LcdBiasSystem(0x03); /*推荐混合率 1:48*/ LcdSetVop(0x32); /*V(6.06) = 3.06 + 0.06*Vop*/ LcdTempCtrl(0x00); /*温度系数 0~3*/ LcdFunctionSet(ACTIVE, H_ADDR, BAS_INS); /*基本指令集*/ LcdDispalyControl((u8)NORMAL_MODE); /*普通模式显示*/ // LcdWriteDC(LCDCMD , 0x21 ); /*扩展指令*/ LcdWriteDC(LCDCMD , 0xc8 ); /*设置偏压*/ LcdWriteDC(LCDCMD , 0x20 ); /*标准指令*/ LcdWriteDC(LCDCMD , 0x0c );/*标准显示模式*/ LcdClsScr(); }
// 发送数据或指令 // DC : 数据或指令 // info : 发送的信息 void LcdWriteDC(u8 DC, uint8_t info) { LcdEnable(TRUE); if( DC == DATA) LCD_DC_HIGH(); else LCD_DC_LOW(); Delaynus(5); SpiSendByte(info); LcdEnable(FALSE); }
/** * @brief Write register value. * @param pData Pointer on the register value * @param Size Size of byte to transmit to the register * @retval None */ void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size) { uint32_t counter = 0; __IO uint32_t data = 0; /* Reset LCD control line CS */ LCD_CS_LOW(); /* Set LCD data/command line DC to High */ LCD_DC_HIGH(); if (Size == 1) { /* Only 1 byte to be sent to LCD - general interface can be used */ /* Send Data */ SPIx_Write(*pData); } else { /* Several data should be sent in a raw */ /* Direct SPI accesses for optimization */ for (counter = Size; counter != 0; counter--) { while(((hnucleo_Spi.Instance->SR) & SPI_FLAG_TXE) != SPI_FLAG_TXE) { } /* Need to invert bytes for LCD*/ *((__IO uint8_t*)&hnucleo_Spi.Instance->DR) = *(pData+1); while(((hnucleo_Spi.Instance->SR) & SPI_FLAG_TXE) != SPI_FLAG_TXE) { } *((__IO uint8_t*)&hnucleo_Spi.Instance->DR) = *pData; counter--; pData += 2; } /* Wait until the bus is ready before releasing Chip select */ while(((hnucleo_Spi.Instance->SR) & SPI_FLAG_BSY) != RESET) { } } /* Empty the Rx fifo */ data = *(&hnucleo_Spi.Instance->DR); UNUSED(data); /* Remove GNU warning */ /* Deselect : Chip Select high */ LCD_CS_HIGH(); }
/** * @brief Writes data to select the LCD register. * This function must be used after st7735_WriteReg() function * @param Data: data to write to the selected register. * @retval None */ void LCD_IO_WriteData(uint8_t Data) { /* Reset LCD control line CS */ LCD_CS_LOW(); /* Set LCD data/command line DC to High */ LCD_DC_HIGH(); /* Send Data */ SPIx_Write(Data); /* Deselect : Chip Select high */ LCD_CS_HIGH(); }
void LCDSend(unsigned char data, unsigned char cd) { LCD_CS_LOW(); if (cd == SEND_CHR) { LCD_DC_HIGH(); } else { LCD_DC_LOW(); } // send data over SPI SEND_BYTE_SPI(); LCD_CS_HIGH(); }
//void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size) void LCD_IO_WriteMultipleData(uint16_t *pData, uint32_t Size) { uint32_t counter = 0; /* Reset LCD control line CS */ LCD_CS_LOW(); /* Set LCD data/command line DC to High */ LCD_DC_HIGH(); if (Size == 1) { /* Only 1 byte to be sent to LCD - general interface can be used */ /* Send Data */ // SPIx_Write(*pData); //LCD_RW_LOW(); LCD_PORT_Value((*pData)>>8); //LCD_RW_HIGH(); Toggle_LCD_RW(); //LCD_RW_LOW(); LCD_PORT_Value(*pData); //LCD_RW_HIGH(); Toggle_LCD_RW(); }
void LCD_IO_WriteData(uint16_t LCDData) { /* Reset LCD control line CS */ LCD_CS_LOW(); /* Set LCD data/command line DC to Low */ LCD_DC_HIGH(); //LCD_RW_LOW(); /* Send Command */ //SPIx_Write(LCDReg); LCD_PORT_Value(LCDData >> 8); Toggle_LCD_RW(); //LCD_RW_HIGH(); //LCD_RW_LOW(); /* Send Command */ //SPIx_Write(LCDReg); LCD_PORT_Value(LCDData); Toggle_LCD_RW(); //LCD_RW_HIGH(); /* Deselect : Chip Select high */ LCD_CS_HIGH(); }