#ifndef __LCD_C
#define __LCD_C
#include "Config.h"
#include "PrjInc.h"
///char strLinClear[18]={' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
///--------------------- ST7567 (128*64)---------------------------------------------------------------------------------------------
void LCD_Delays(unsigned short bTick)
{
unsigned short j,k;
for(j=0;j<bTick;j++)
for(k=0;k<100;k++);
}
/********************************************************************
** 函数名称:LCD_ST7565_CMD
** 函数功能:写指令进LCD
** 输入参数:CMD LCD指令
** 输出参数:
** 返 回 值:
** 其它说明:
*********************************************************************/
void LCD_ST7565_CMD(unsigned char bCmd)
{
unsigned char i;
LCD_ST7565_CD_Low();
LCD_ST7565_CS_Low();
for(i = 0; i < 8; i++)
{
LCD_ST7565_SCLK_Low();
LCD_Delays(2);
if(bCmd & 0x80)
{LCD_ST7565_Data_High();}
else
{LCD_ST7565_Data_Low();}
LCD_ST7565_SCLK_High();
bCmd <<= 1;
}
LCD_ST7565_CS_High();
}
/********************************************************************
** 函数名称:Screen_Write_Buf
** 函数功能:写数据进LCD
** 输入参数:data_ LCD指令
** 输出参数:
** 返 回 值:
** 其它说明:
*********************************************************************/
void LCD_Screen_Write(unsigned char bData)
{
unsigned char i;
LCD_ST7565_CD_High();
LCD_ST7565_CS_Low();
for(i = 0; i < 8; i++)
{
LCD_ST7565_SCLK_Low();
if(bData & 0x80)
{LCD_ST7565_Data_High();}
else
{LCD_ST7565_Data_Low();}
LCD_ST7565_SCLK_High();
bData <<= 1;
}
LCD_ST7565_CS_High();
}
/********************************************************************
** 函数名称:Screen_Pos_Set
** 函数功能:设定屏幕位置
** 输入参数:x 列开始位置 y 行开始位置
** 输出参数:
** 返 回 值:
** 其它说明:
*********************************************************************/
void LCD_Screen_SetPos(unsigned char x, unsigned char y)
{
x--;
y--;
LCD_ST7565_CMD(0xB0 + y); ////---设置显示起始页
LCD_ST7565_CMD(0x10 + ((x >> 4) & 0x0F));
LCD_ST7565_CMD(x & 0x0F);
}
/********************************************************************
** 函数名称:Screen_Fill
** 函数功能:填充屏幕
** 输入参数:chr_ 要填充的字符
** 输出参数:
** 返 回 值:
** 其它说明:填充 0x00 相当于清屏
*********************************************************************/
void LCD_Screen_Fill(unsigned char chr_)
{
unsigned char i,j;
for(i=0;i<9;i++)
{
LCD_ST7565_CMD(0xB0+i);
LCD_ST7565_CMD(0x10);
LCD_ST7565_CMD(0x00);
for(j=0;j<132;j++){LCD_Screen_Write(chr_);}
}
}
void LCD_Screen_Clear(void)
{
LCD_Screen_Fill(0);
}
/********************************************************************
** 函数名称:LCD_ST7565_Initial
** 函数功能:初始化LCD模块
** 输入参数:无
** 输出参数:无
** 返 回 值:无
** 其它说明:无
*********************************************************************/
void LCD_ST7565_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = LCD_ST7565_CS_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd =GPIO_PuPd_UP; ///--- GPIO_PuPd_NOPULL;
GPIO_Init(LCD_ST7565_CS_Port, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = LCD_ST7565_RST_Pin |LCD_ST7565_CD_Pin |LCD_ST7565_SCLK_Pin |LCD_ST7565_Data_Pin;
GPIO_Init(LCD_ST7565_RST_Port, &GPIO_InitStructure);
LCD_Delays(20);
LCD_ST7565_RST_Low(); ///--- 拉低LCD 复位脚 复位屏幕---
LCD_Delays(20);
LCD_ST7565_RST_High(); ///--- 完成复位开始工作---
LCD_ST7565_CMD(0xE2);
LCD_Delays(20);
LCD_ST7565_CMD(0x2C); ///---升压步聚1---
LCD_Delays(20);
LCD_ST7565_CMD(0x2E); ///---升压步聚2---
LCD_Delays(20);
LCD_ST7565_CMD(0x2F); ///---升压步聚3---
LCD_Delays(20);
LCD_ST7565_CMD(0x24); ///---粗调对比度,可设置范围20~27---
LCD_ST7565_CMD(0x81); ///---微调对比度CMD---
LCD_ST7565_CMD(0x15); ///---微调对比度的值,可设置范围0x00~0x3F---
LCD_ST7565_CMD(0xA2); ///---1/9偏压比(bias)---
LCD_ST7565_CMD(0xC8); ///---行扫描顺序:从上到下---
LCD_ST7565_CMD(0xA0); ///---列扫描顺序:从左到右---
LCD_ST7565_CMD(0x40); ///---起始行:从第一行开始---
LCD_Screen_Fill(0x00);
LCD_ST7565_CMD(0xAF); ///---开显示---
}
///--------------------------------------------------------------------------
///--- x--->(1~120) 列 开始位置 /\/\ y---> (1~7) 行 开始位置----
///--------------------------------------------------------------------------
void LCD_Display_Str8x16(unsigned short bX, unsigned short bY, char *bStr)
{
unsigned short i=0,j,k,n;
while(bStr[i]>0x00)
{
if((bStr[i]>=0x20)&&(bStr[i]<=0x7E))
{
j = bStr[i] - 0x20;
for(n=0;n<2;n++)
{
LCD_Screen_SetPos(bX, bY + n);
for(k = 0; k < 8; k++) { LCD_Screen_Write(ascii_table8x16[j][k+8*n]); }
}
i++;
bX +=8;
}
else
{
i++;
}
}
}
///==================display a string of ASCII character,font style:5*8 dots================
///--------------------------------------------------------------------------
///--- x--->(1~120) 列 开始位置 /\/\ y---> (1~7) 行 开始位置----
///--------------------------------------------------------------------------
void LCD_Display_Str5x8(unsigned short pX,unsigned short cY,char *bStr)
{
unsigned short i=0,j,k;
while(bStr[i]>0x00)
{
if((bStr[i]>=0x20)&&(bStr[i]<0x7E))
{
j=bStr[i]-0x20;
LCD_Screen_SetPos(pX,cY);
for(k=0;k<5;k++)
{
LCD_Screen_Write(ascii_table5x8[j][k]); ///---显示5x7的ASCII字到LCD上,y为页地址,x为列地址,最后为数据----
}
i++;
pX+=6;
}
else
{
i++;
}
}
}
///---------------------------------------------------------------------------
void IsrLCD_Display(void)
{
char str[10];
///------------------------------------------------
if((bWaitingEnable >0)&&(dWaitTimeCnts !=dWaitTimCntBaks))
{
dWaitTimCntBaks = dWaitTimeCnts;
sprintf(str," %3d%.2s ",dWaitTimeCnts,"s");
LCD_Display_Str8x16(24, 4, str);
if(0== dWaitTimeCnts)
{
bWaitingEnable =0;
bTestProIndex =0;
}
}
else
{
if(bWaitingEnable ==0 )
{
LCD_Display_Str8x16(24, 4, cTestPro[bTestProIndex]);
}
}
///-------------------------------------------
sprintf(str,"%.3s%1d","CH:",bMachAddr);
LCD_Display_Str8x16(1, 1, str);
LCD_Display_Str8x16(48, 1, cPrjName[bPrjIndex]);
///----------------------------------------------
sprintf(str,"%.1f",(float)dCurFanTemper/100);
LCD_Display_Str5x8(102,8,str);
///------------------------------------------------
}
///--------------------------------------------------------------------------
unsigned short LCD_ProcessEvent(unsigned char task_id, unsigned short events)
{
uint8_t bRet=0;
// if(IsError(&gInsErr))
// {
// return 0;
// }
///---- ToDo ----------------------------------------
///------- Finish Task ---------------------------------
//if(IsError(&gInsErr))
//{
// SetCurTaskFinish(&gCurTaskParam);
//}
//else
//{
// Osal_OveCurTaskArr(&gCurTaskParam);
//}
//if ( events & SYS_EVENT_MSG )
//{
// return unprocessed events
// return (events ^ SYS_EVENT_MSG);
//}
// Osal_OveCurTaskArr(&gCurTaskParam);
return bRet;
}
///---------------------------------------------------------------------------------
#endif
ST7567_LCD.zip
需积分: 50 132 浏览量
2020-03-09
17:03:48
上传
评论 2
收藏 3KB ZIP 举报
mk205
- 粉丝: 5
- 资源: 25
最新资源
- 基于matlab实现多车辆车辆路径问题,用遗传算法编程,保证可用.rar
- 基于matlab实现多层极限学习机实现手写体识别,准确率超过99%.rar
- 基于matlab实现电力系统最优潮流程序,可以应用于电力市场下的最优潮流计算 适合电力系统专业的同仁使用.rar
- 串行通信的通信协议串口协议串行通信的通信协议串口协议
- Vue构建交互式的单页面应用程序Vue构建交互式的单页面应用程序
- Spring Boot快速搭建和部署应用程序
- Redis开源的高性键值存储系统广泛应用于缓存、实时消息传递
- Qt跨平台的应用程序开发框架Qt跨平台的应用程序开发框架
- 单片机是集成处理器、存储器和输入输出设备
- 深度学习机器习方法模仿人脑神经网络深度学习机器习方法模仿人脑神经网络
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈