由浅入深,蓝牙4.0/BLE协议栈开发攻略大全(1)
HAL_SPI_TRANSFER_MSB_FIRST | HAL_SPI_CLOCK_PHA_0 | HAL_SPI_CLOCK_POL_LO | 0x0F;
U1BAUD = 0xFF;
// CS RS 配置为输出
HAL_CONFIG_IO_OUTPUT(HAL_LCD_RS_PORT, HAL_LCD_RS_PIN, 1);
HAL_CONFIG_IO_OUTPUT(HAL_LCD_CS_PORT, HAL_LCD_CS_PIN, 1);
SoftWaitUs(15000); // 15 ms
LCD12864_Cmd(LCD_CMD_SOFT_RESET); //软复位
SoftWaitUs(15000); // 15 ms
LCD12864_Cmd(LCD_CMD_POWER_ONE); //升压步聚1
SoftWaitUs(15); // 15 us
LCD12864_Cmd(LCD_CMD_POWER_TWO); //升压步聚2
SoftWaitUs(15); // 15 us
LCD12864_Cmd(LCD_CMD_POWER_THREE); //升压步聚3
SoftWaitUs(150); // 15 us
LCD12864_Cmd(LCD_CMD_CONTRAST_ONE_LEVEL); //粗调对比度,可设置范围0x20~0x27
LCD12864_Cmd(LCD_CMD_CONTRAST_TWO_CMD); //微调对比度
LCD12864_Cmd(0x3a); //0x1a,微调对比度的值,可设置范围0x00~0x3f
LCD12864_Cmd(LCD_CMD_BIAS_SET); // 1/9偏压比(bias)
LCD12864_Cmd(LCD_CMD_LINE_NORMAL); //行扫描顺序:从上到下
LCD12864_Cmd(LCD_CMD_ROW_ADDR_REVERSE); //列扫描顺序:从左到右
LCD12864_Cmd(LCD_CMD_BEGIN_LINE); //起始行:第一行开始
LCD12864_Cmd(LCD_CMD_DISPLAY_ON); //打开显示
LCD12864_Cmd(LCD_CMD_DISPLAY_POINT_NORMAL);
LCD12864_Cmd(LCD_CMD_DISPLAY_NORMAL); //设置为正显模式
SoftWaitUs(150); // 150 us
}
static void LCD12864_SetAddr(uint8 line, uint8 col)
{
uint8 ucLine, ucRow;
//line += 5;
col += 4;
if((line >= LCD12864_MAX_LINE) || (col >= LCD12864_MAX_ROW))
{
return;
}
ucLine = LCD_CMD_PAGE_LINE | (line&0x0f);
LCD12864_Cmd(ucLine);
SoftWaitUs(15);
ucRow = LCD_CMD_ROW_HIG | (col>>4);
LCD12864_Cmd(ucRow);
SoftWaitUs(15); // 15 us
ucRow = LCD_CMD_ROW_LOW | (col&0x0f);
LCD12864_Cmd(ucRow);
SoftWaitUs(15); // 15 us
}
static void LCD12864_Dis5X8(char ch)
{
uint8 ucCnt;
if((ch >= 0x20)&&(ch <0x7f))
{
uint8 ucChar = ch - 0x20;
for(ucCnt=0; ucCnt《5; ucCnt++)
{
LCD12864_Dat( aucAsciiTable5x7[ucChar][ucCnt]);
}
//LCD12864_Dat(0x00);
}
else if(ch==0x00) //不需要显示,清空指定位置
{
for(ucCnt=0; ucCnt《5; ucCnt++)
{
LCD12864_Dat(0x00);
}
}
LCD12864_Dat(0x00);
}
void LCD12864_Clear(void)
{
uint8 ucLine, ucRow;
for(ucLine=0; ucLine《LCD12864_MAX_LINE; ucLine++)
{
LCD12864_SetAddr(ucLine, 0);
for(ucRow=0; ucRow《LCD12864_MAX_ROW; ucRow++)
{
LCD12864_Dat(0x00);
}
}
}
void LCD12864_DisChar(uint8 line, uint8 col, char ch)
{
if (( line <HAL_LCD_MAX_LINES)&&(col <HAL_LCD_MAX_CHARS))
{
LCD12864_SetAddr(line, col*HAL_LCD_FONT_ROWS);
LCD12864_Dis5X8(ch);
}
}
void LCD12864_DisStr(uint8 line, char* pStr)
{
uint8 ucCnt = 0;
for ( ucCnt = 0 ; ucCnt <HAL_LCD_MAX_CHARS; ucCnt++ )
{
if ( ’\0‘ == *pStr )
{
break;
}
LCD12864_DisChar( line, ucCnt, pStr[ucCnt]);
}
for ( ; ucCnt <HAL_LCD_MAX_CHARS; ucCnt++ )
{
LCD12864_DisChar( line, ucCnt, 0);
}
}
主程序:
int main(void)
{
/* 启动外部晶振 */
SysStartXOSC();
/* LCD12864的初始化 */
LCD12864_Init();
/* 清屏 */
LCD12864_Clear();
while(1)
{
/* 显示字符 */
LCD12864_DisStr(3, "ShenZhenShiManTouKeJi");
}
return 0;
}
这样我们就点亮的LCD12864屏幕
- 主流蓝牙BLE控制芯片详解(3):创杰 IS1685S(07-18)
- 苹果光环加持,蓝牙Beacon技术成室内定位应用最大黑马(08-02)
- 主流蓝牙BLE控制芯片详解(4):Nordic nRF51822(07-20)
- 蓝牙BLE之室内定位iBeacon应用测验(08-02)
- 由浅入深,蓝牙4.0/BLE协议栈开发攻略大全(5)(08-02)
- 由浅入深,蓝牙4.0/BLE协议栈开发攻略大全(2)(07-18)