|
最近在做LCD controller, 貼一個(gè)ST7796初始化代碼供大家參考。
單片機(jī)源程序如下:
- /*
- * ST7796.c
- *
- * Created on: Nov 29, 2018
- * Author: 20150287
- */
- #include "ST7796.h"
- #include "fsl_debug_console.h"
- status_t writeTable(st7796_cmd_t *cmdTable, uint32_t numCmds)
- {
- while(numCmds--)
- {
- writeCommand(cmdTable++);
- }
- return kStatus_Success;
- }
- /*-----------------------------------------------------------*/
- status_t writeData(uint8_t data, uint8_t type, uint32_t delay)
- {
- uint8_t tx[BUFFER_SIZE] = {type, data};
- /* after tx wait delay ms */
- APP_SPI_Write(tx, delay);
- return kStatus_Success;
- }
- /*-----------------------------------------------------------*/
- status_t writeCommand(st7796_cmd_t *cmd)
- {
- uint8_t numArgs = cmd->numArgs;
- uint8_t *args = cmd->args;
- writeData(cmd->value, ST7796_DC_CMD, 0U);
- while(numArgs--)
- {
- writeData(*args++, ST7796_DC_DATA, (numArgs > 0) ? 0U : cmd->delay);
- }
- return kStatus_Success;
- }
- /*-----------------------------------------------------------*/
- void APP_ST7796_Init(void)
- {
- /* cmds follows the format:
- *
- * command
- * post command delay
- * number of arguments/parameters
- * array of arguments
- *
- * */
- st7796_cmd_t cmds[] = {
- {
- ST7796_SWRESET,
- 150U,
- 0U,
- {},
- },
- {
- ST7796_SLPOUT,
- 150U,
- 0U,
- {},
- },
- {
- ST7796_IFPXFMT,
- 12U,
- 1U,
- {(ST7796_IFPXFMT_RGB_16 | ST7796_IFPXFMT_CTRL_16)},
- },
- {
- ST7796_IFMODE,
- 12U,
- 1U,
- {0x00},
- },
- {
- ST7796_DFC,
- 12U,
- 1U,
- {0xA2},
- },
- {
- ST7796_NORON,
- 12U,
- 0U,
- {},
- },
- {
- ST7796_INVON,
- 12U,
- 0U,
- {},
- },
- {
- ST7796_INVOFF,
- 12U,
- 0U,
- {},
- },
- {
- ST7796_IDMOFF,
- 12U,
- 0U,
- {},
- },
- {
- ST7796_WRCTRLD,
- 12U,
- 1U,
- {0x00 | ST7796_WRCTRLD_BCTRL_ON | ST7796_WRCTRLD_DD_ON | ST7796_WRCTRLD_BL_ON},
- },
- {
- ST7796_DISPON,
- 500U,
- 0U,
- {},
- },
- {
- ST7796_WRDISBV,
- 12U,
- 1U,
- {0x7F},
- },
- };
- PRINTF("ST7796: Starting setup.\r\n");
- writeTable(cmds, 12U);
- PRINTF("ST7796: Setup complete.\r\n");
- return;
- }
- /*-----------------------------------------------------------*/
復(fù)制代碼
|
|