📄 drv_lcd.c
字号:
#include "sys_def.h"
#include "drv_lcd.h"
/*******************************************************************************
// 常量定义
*******************************************************************************/
#define LCD_CS1 BIT0 /* LCD片选 */
#define LCD_RES BIT1 /* LCD复位 */
#define LCD_A0 BIT2 /* 数据命令选择 */
#define LCD_SDI BIT3 /* SPI 数据 */
#define LCD_SCK BIT5 /* SPI 时钟 */
#define SIMO1 BIT3
#define SOMI1 BIT4
#define UCLK1 BIT5
/*******************************************************************************
// 外部变量定义
*******************************************************************************/
UCHAR aFrameBuffer[8][128]; /* 帧缓冲 */
/*******************************************************************************
// 外部函数定义
*******************************************************************************/
void LcdInit()
{
//LPI Init
P4DIR |= LCD_CS1 + LCD_RES + LCD_A0 + LCD_SDI + LCD_SCK;//设置Port4输出模式
P4SEL |= SIMO1 + SOMI1 + UCLK1; // 设置管脚为第二功能
U1CTL = CHAR + SYNC + MM + SWRST; // 8-bit SPI master
U1TCTL |= CKPL + SSEL1 + STC; // SMCLK作为SPI时钟, 三线模式
U1BR0 = 0x04; // SMCLK/2波特率
U1BR1 = 0x00;
U1MCTL = 0x00; // Clear modulation
ME2 |= USPIE1; // 使能 USART1 SPI模块
U1CTL &= ~SWRST; // 清除串口复位信号
//LCD Init
P4OUT &= ~LCD_RES;
P4OUT |= LCD_RES;
LcdSendCommand(LCD_RESET);
LcdSendCommand(LCD_ON);
LcdSendCommand(LCD_PWR_ALL); // 设置上电控制模式
// 电量设置模式(显示亮度)
LcdSendCommand(LCD_LUM_MOD);
LcdSendCommand(LCD_LUM_VLU);
LcdSendCommand(LCD_VDD_RST); // V5电压调节电阻设置
LcdSendCommand(LCD_VDD_9TH); // 偏压设置
LcdSendCommand(LCD_COM_REV); // Com扫描方式设置
LcdSendCommand(LCD_SEG_NML); // 段横向方向选择
LcdSendCommand(LCD_SRN_ON); // 全屏变暗指令
LcdSendCommand(LCD_CLR_NML); // 正相显示控制指令
return;
}
void LcdSendCommand(UCHAR ucCommand)
{
volatile UCHAR uc;
P4OUT &= ~LCD_CS1;
P4OUT &= ~LCD_A0;
while (!(IFG2 & UTXIFG1));
U1TXBUF = ucCommand;
while (!(IFG2 & UTXIFG1));
for (uc = 2; uc > 0; uc--);
P4OUT |= LCD_CS1;
return;
}
void LcdSendData(UCHAR ucData)
{
volatile UCHAR uc;
P4OUT &= ~LCD_CS1;
P4OUT |= LCD_A0;
while (!(IFG2 & UTXIFG1));
U1TXBUF = ucData;
while (!(IFG2 & UTXIFG1));
for (uc = 2; uc > 0; uc--);
P4OUT |= LCD_CS1;
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -