久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標題:
ST7565 128x64 LCD驅動程序
[打印本頁]
作者:
leo_chen_001
時間:
2023-9-2 22:22
標題:
ST7565 128x64 LCD驅動程序
普通128x64點陣LCD點陣顯示,采用ST7565
Init_LCD_ST7565();
LCD_CLS_ST7565(0);
LCD_disp_printR_ST7565(Test",0,0,4);
LCD_disp_printR_ST7565(“2023/07/03",0,2,10);
LCD_Driver_7565.c
// LCD_128X64
// Driver: st7565/st7567
// Mode: 4 line SPI
// WR,RD : GND
// leo_20160120
#define LCD_DRIVER_7565_C
#include "LCD_DRIVER_7565.h"
#include "L_ASCII_8x8.h"
#include "L_HZ_16x16.h"
// #include "L_BMP.h"
xdata u8 Dis_u16_Buf[5];
xdata u8 Dis_u8_Buf[3];
xdata u8 Dis_Sensor_Buf[7];
//當前字符顯示的位置
//unsigned char Lcd_Charcter_CurrentX,Lcd_Charcter_CurrentY;
//當前像素顯示位置
unsigned char Lcd_CurrentX,Lcd_CurrentY;
//圖像反色顯示 0 否 1是
unsigned char LCD_DisplayReserve_Driver;
//--------------------------------------------------------------------------
//串口移位輸出
//--------------------------------------------------------------------------
void SPI_Write_ST7565(char datain)
{
unsigned char i;
unsigned char Series,Temp;
Series = datain;
for(i=8;i>0;i--)
{
LCD_SCK_L();
Temp=Series & 0x80;
if(Temp)
{
LCD_SDA_H();
}
else
{
LCD_SDA_L();
}
LCD_SCK_H();
Series = Series << 1;
}
}
/***********************************
** 函數名稱: Write_Data
** 功能描述: 傳送數據
** 輸 入: dat
** 輸 出 : 無
** 全局變量:無
** 調用模塊: Busy,
******************************************/
void Write_Data_ST7565(unsigned char dat)
{
LCD_CS_L();
LCD_DC_H(); //A0=1,數據
SPI_Write_ST7565(dat);
LCD_CS_H();
return;
}
/***********************************
** 函數名稱: Write_Instruction
** 功能描述: 傳送命令
** 輸 入: dat
** 輸 出 : 無
** 全局變量:無
** 調用模塊: Busy,
******************************************/
void Write_Instruction_ST7565(unsigned char cmd)
{
LCD_CS_L();
LCD_DC_L(); //A0=0,命令
SPI_Write_ST7565(cmd);
LCD_CS_H();
return;
}
//==============================================================================高一級函數
//設置像素顯示坐標(x:0-127,y:0-7)
void LCD_setpos_ST7565(unsigned char Lx,unsigned char Ly)
{
Write_Instruction_ST7565(0xB0|Ly);// Page(Row)
Write_Instruction_ST7565((0x10|(Lx>>4)));
Write_Instruction_ST7565((0x0f&Lx));
Lcd_CurrentX=Lx;
Lcd_CurrentY=Ly;
}
// ************************************************************************************************************
//設置字符位置(x:0-8,y:0-3)
void LCD_setCharpos_ST7565(unsigned char Lx,unsigned char Ly)
{
//當前像素顯示位置
/*
// 8*8
Lcd_CurrentX=Lx*16;
Lcd_CurrentY=Ly*2;
*/
// 4*4
Lcd_CurrentX=Lx*8;
Lcd_CurrentY=Ly*1;
LCD_setpos_ST7565(Lcd_CurrentX,Lcd_CurrentY);
}
// ************************************************************************************************************
//清屏
void LCD_CLS_ST7565(char value)
{
unsigned char i,n;
for(i=0;i<9;i++)
{
LCD_setpos_ST7565(0,i);
for(n=0;n<128;n++)
{
Write_Data_ST7565(value);
}
}
}
// ************************************************************************************************************
//顯示BMP圖片
void LCD_DisplayBMP_ST7565(const unsigned char *PicData) //信息顯示
{
unsigned char BMPwithLen,BMPheightLen;
unsigned char BMPwith;
unsigned char BMPheight;
BMPwith=*PicData;
PicData++;
BMPheight=(*PicData)/8;
PicData++;
//BMPLen=BMPheight/8*BMPwith
for(BMPheightLen=0;BMPheightLen<BMPheight;BMPheightLen++)
{
// Lcd_CurrentY++;
LCD_setpos_ST7565(Lcd_CurrentX,Lcd_CurrentY);
for(BMPwithLen=0;BMPwithLen<BMPwith;BMPwithLen++)
{
//圖像反色顯示 0 否 1是
if (LCD_DisplayReserve_Driver==0)
{
Write_Data_ST7565(*PicData);
}
else
{
Write_Data_ST7565(~(*PicData));
}
PicData++;
}
Lcd_CurrentY++;
}
}
// ************************************************************************************************************
void LCD_disp_DisplayImage_ST7565(const unsigned char * PicData,unsigned char PicLen) //信息顯示
{
for(;PicLen>0;PicLen--)
{
//圖像反色顯示 0 否 1是
if (LCD_DisplayReserve_Driver==0)
{
Write_Data_ST7565(*PicData);
}
else
{
Write_Data_ST7565(~(*PicData));
}
PicData++;
};
}
// ************************************************************************************************************
//顯示一個Unicode
void LCD_disp_Putchar_ST7565(unsigned int uChar)
{
unsigned int i;
const unsigned char *p;
if(uChar<128)
{
//for(i=0;i != ENGLISHCHARNUMBER;i++)
//{
//if(uChar==EnglishCode[i][0])
//{
p=(uChar-0x20)*(ENGLISHCHARLegth)+&nAsciiDot[0];
LCD_disp_DisplayImage_ST7565(p, ENGLISHCHARLegth/2);
Lcd_CurrentY++;
//設置像素顯示坐標(y:0-7)
LCD_setpos_ST7565(Lcd_CurrentX,Lcd_CurrentY);
LCD_disp_DisplayImage_ST7565(p+(ENGLISHCHARLegth/2),(ENGLISHCHARLegth/2));
Lcd_CurrentY--;
Lcd_CurrentX+=8;
//設置像素顯示坐標(y:0-7)
LCD_setpos_ST7565(Lcd_CurrentX,Lcd_CurrentY);
//break;
//}
//}
}
else
{
for(i=0;i!=GB_ZK_NUM;i++)
{
if(uChar==(GB_16[i].Index[0]*256+GB_16[i].Index[1]))
{
//分別在兩頁顯示
LCD_disp_DisplayImage_ST7565(GB_16[i].Msk,(CHINESECHARlegth/2));
Lcd_CurrentY++;
//設置像素顯示坐標(y:0-7)
LCD_setpos_ST7565(Lcd_CurrentX,Lcd_CurrentY);
LCD_disp_DisplayImage_ST7565(GB_16[i].Msk+(CHINESECHARlegth/2),(CHINESECHARlegth/2));
Lcd_CurrentY--;
Lcd_CurrentX+=16;
//設置像素顯示坐標(y:0-7)
LCD_setpos_ST7565(Lcd_CurrentX,Lcd_CurrentY);
break;
}
}
}
}
// ************************************************************************************************************
//圖像反色顯示 0 否 1是,執行此命令后的所有操作均是按照設置顯示
void LCD_disp_SetReverse_ST7565(unsigned char ReverseTrue)
{
//圖像反色顯示 0 否 1是
if (ReverseTrue==0)
{
LCD_DisplayReserve_Driver=0;
}
else
{
LCD_DisplayReserve_Driver=1;
}
}
// ************************************************************************************************************
//對比度設置
void Set_Contrast_Control_ST7565(unsigned char Level)
{
unsigned char Num,Temp1,Temp2;
Temp1 = (Level/16)<<4;
switch(Level%16)
{
case 10:
Temp2 = 0x0a;
break;
case 11:
Temp2 = 0x0b;
break;
case 12:
Temp2 = 0x0c;
break;
case 13:
Temp2 = 0x0d;
break;
case 14:
Temp2 = 0x0e;
break;
case 15:
Temp2 = 0x0f;
break;
default:
Temp2 = Level%16;
break;
}
Num = Temp1|Temp2;
Write_Instruction_ST7565(0x81);
Write_Instruction_ST7565(Num);
}
// ************************************************************************************************************
//初始化LCD屏
void Init_LCD_ST7565(void)
{
// CLRBit(RST); // RST=0;
// LCD_DelayMS(50);
// SETBit(RST); // RST=1;
// LCD_DelayMS(50);
LCD_RST_L();
Delay_nms(10);
LCD_RST_H();
Delay_nms(10);
Write_Instruction_ST7565(0xa2); // lcd bias select 1/9 BIAS
// Write_Instruction(0xa1); // ADC select,REVERSE 127-->0(a0,a1)
Write_Instruction_ST7565(0xa0); // ADC=0
// Write_Instruction(0xc0); // com select,NORMAL 0-->63(c8,c0)
Write_Instruction_ST7565(0xc8); // Common output mode select= reverse
Write_Instruction_ST7565(0x26); // RESISTOR RATIO
Write_Instruction_ST7565(0x81); // ELECTRONIC VOLUME mode setting 100B 對比度命令
// Write_Instruction_ST7565(0x00); // Set reference voltagel register 對比度數值 // leo_20170622
Write_Instruction_ST7565(0x0A); // Set reference voltagel register 對比度數值 // leo_20170622
// Write_Instruction_ST7565(0x28); // Set reference voltagel register 對比度數值 // LM6060C
// Write_Instruction_ST7565(0x12); // Set reference voltagel register 對比度數值 ,RYX207, leo_20170512
Write_Instruction_ST7565(0x2f); // power control(VB,VR,VF=1,1,1)
Delay_nms(10);
Write_Instruction_ST7565(0x40); // display start line=0
Write_Instruction_ST7565(0xa6); // normal display
Write_Instruction_ST7565(0xa4); // Duisplay all point = off
Write_Instruction_ST7565(0xaf); // set display on
Write_Instruction_ST7565(0xf8); // set booster ratio = 5x
// Write_Instruction(0x00);
Write_Instruction_ST7565(0x01); // (two byte command)
/*
Write_Instruction(0xaf); // display on
Write_Instruction(0x40); // display start line=0
Write_Instruction(0xa0); // ADC=0
Write_Instruction(0xa6); // normal display
Write_Instruction(0xa4); // Duisplay all point = off
Write_Instruction(0xa2); // LCD bias = 1/9
Write_Instruction(0xc8); // Common output mode select= reverse
Write_Instruction(0x2f); // Power control = all on
Write_Instruction(0xf8); // Booster Ratio = 5x
Write_Instruction(0x01); // (two byte command)
Write_Instruction(0x81); //ELECTRONIC VOLUME mode setting 100B 對比度命令
Write_Instruction(0x28);
*/
//當前像素顯示位置
Lcd_CurrentX=0;
Lcd_CurrentY=0;
//圖像反色顯示 0 否 1是
LCD_DisplayReserve_Driver=0;
// LCD_DisplayReserve_Driver=1; // 20170622
// LCD_setpos_Driver(Lcd_CurrentX,Lcd_CurrentY);
}
void LCD_Set_Place_ST7565(unsigned char x,unsigned char y)
{
if(y>LCD_MAX_Y) y=LCD_MIN_Y;
if(x>LCD_MAX_X) x=LCD_MIN_X;
LCD_setCharpos_ST7565(x,y);
}
// ************************************************************************************************************
void LCD_disp_printR_ST7565(unsigned char *s,unsigned char x,unsigned char y,u8 length) // 顯示漢字或英文字符
{
u8 temp;
unsigned int i;
LCD_Set_Place_ST7565(x,y);
for (temp=0;temp<length;temp++)
{
i=s[temp];
if(s[temp] > 127)
{
temp++;
i=i*256+s[temp];
}
LCD_disp_Putchar_ST7565(i);
}
}
// ******
void LCD_7565_Power_ON(void)
{
Write_Instruction_ST7565(0xAF); // ST7565 Power ON
}
// ******
void LCD_7565_Power_OFF(void)
{
Write_Instruction_ST7565(0xAE); // ST7565 Power OFF
}
// ************************************************************************************************************
/*
Init_LCD_ST7565();
LCD_CLS_ST7565(0);
LCD_disp_printR_ST7565("leo 2016/01/20",0,0);
Delay_nms(1000);
LCD_CLS_ST7565(0);
LCD_disp_printR_ST7565("科技",2,0);
Delay_nms(1000);
// LCD_disp_SetReverse_ST7565();
LCD_DisplayBMP_ST7565(nBitmapDot_BMP1);
INT_Dec_disposal(Pressure,Dis_u16_Buf);
LCD_disp_printR_ST7565(Dis_u16_Buf,5,0,5);
INT_Dec_disposal(Motor_Current,Dis_u16_Buf);
LCD_disp_printR_ST7565(Dis_u16_Buf,5,2,5);
Dec_disposal(Temperature,Dis_u8_Buf);
LCD_disp_printR_ST7565(Dis_u8_Buf,5,4,3);
Dec_disposal(Humidity,Dis_u8_Buf);
LCD_disp_printR_ST7565(Dis_u8_Buf,5,6,3);
LCD_7565_Power_ON();
LCD_7565_Power_OFF();
*/
復制代碼
LCD_DRIVER_7565.h
// LCD_128X64
// Driver: st7565/st7567
// Mode: 4 line SPI
// WR,RD : GND
// leo_20160120
#ifndef LCD_DRIVER_7565_H
#define LCD_DRIVER_7565_H
#include "includes.h"
// ******
#define LCD_PORT_1 P1
#define LCD_PORT_2 P2
// ******
#define IO_LCD_Backlight P14
#define LCD_Backlight_ON() IO_LCD_Backlight=1
#define LCD_Backlight_OFF() IO_LCD_Backlight=0
/*
#define LCD_Backlight_pin GPIO_PIN_2
#define LCD_Backlight_ON() LCD_PORT_1&=~LCD_Backlight_pin
#define LCD_Backlight_OFF() LCD_PORT_1|=LCD_Backlight_pin
#define LCD_Backlight_Reverse() LCD_PORT_1^= LCD_Backlight_pin
*/
#define LCD_CS_Pin GPIO_PIN_3
#define LCD_RST_Pin GPIO_PIN_0
#define LCD_DC_Pin GPIO_PIN_3
#define LCD_SCK_Pin GPIO_PIN_4
#define LCD_SDA_Pin GPIO_PIN_5
#define LCD_CS_H() LCD_PORT_1|= LCD_CS_Pin
#define LCD_CS_L() LCD_PORT_1&=~LCD_CS_Pin
#define LCD_RST_H() LCD_PORT_2|= LCD_RST_Pin
#define LCD_RST_L() LCD_PORT_2&=~ LCD_RST_Pin
#define LCD_DC_H() LCD_PORT_2|= LCD_DC_Pin
#define LCD_DC_L() LCD_PORT_2&=~ LCD_DC_Pin
#define LCD_SCK_H() LCD_PORT_2|=LCD_SCK_Pin
#define LCD_SCK_L() LCD_PORT_2&=~LCD_SCK_Pin
#define LCD_SDA_H() LCD_PORT_2|= LCD_SDA_Pin
#define LCD_SDA_L() LCD_PORT_2&=~ LCD_SDA_Pin
#define ENGLISHCHARLegth ((8*16)/8/1)
#define CHINESECHARlegth ((16*16)/8/1)
/*
//以8*8字符計算,顯示屏橫向、縱向可以顯示的點陣坐標;左、上、右、下以及當前的位置坐標
#define LCD_MAX_X 7
#define LCD_MAX_Y 3
*/
//以4*4字符計算,顯示屏橫向、縱向可以顯示的點陣坐標;左、上、右、下以及當前的位置坐標
#define LCD_MAX_X 15
#define LCD_MAX_Y 7
#define LCD_MIN_X 0
#define LCD_MIN_Y 0
extern xdata u8 Dis_u16_Buf[];
extern xdata u8 Dis_u8_Buf[];
extern xdata u8 Dis_Sensor_Buf[];
//當前字符顯示的位置
//unsigned char Lcd_Charcter_CurrentX,Lcd_Charcter_CurrentY;
//當前像素顯示位置
extern unsigned char Lcd_CurrentX,Lcd_CurrentY;
//圖像反色顯示 0 否 1是
extern unsigned char LCD_DisplayReserve_Driver;
#if defined LCD_DRIVER_7565_C
void Init_LCD_ST7565(); // 初始化LCD屏
void LCD_CLS_ST7565(char value); // 清屏
void Set_Contrast_Control_ST7565(unsigned char Level); // 設置對比度
void LCD_disp_Putchar_ST7565(unsigned int uChar); // 顯示一個Unicode
void LCD_disp_SetReverse_ST7565(unsigned char ReverseTrue); // 圖像反色顯示 0 否 1是,執行此命令后的所有操作均是按照設置顯示
void LCD_DisplayBMP_ST7565(const unsigned char *PicData); // 顯示BMP圖片
void LCD_setpos_ST7565(unsigned char Lx,unsigned char Ly); // 設置像素顯示坐標(x:0-127,y:0-7)
void LCD_Set_Place_ST7565(unsigned char x,unsigned char y);
void LCD_setCharpos_ST7565(unsigned char Lx,unsigned char Ly); // 設置字符位置(x:0-8,y:0-3)
void LCD_disp_printR_ST7565(unsigned char *s,unsigned char x,unsigned char y,u8 length); // display 中英文字符
void Write_Data_ST7565(unsigned char dat);
void LCD_7565_Power_ON(void);
void LCD_7565_Power_OFF(void);
#else
extern void Init_LCD_ST7565(); // 初始化LCD屏
extern void LCD_CLS_ST7565(char value); // 清屏
extern void Set_Contrast_Control_ST7565(unsigned char Level); // 設置對比度
extern void LCD_disp_Putchar_ST7565(unsigned int uChar); // 顯示一個Unicode
extern void LCD_disp_SetReverse_ST7565(unsigned char ReverseTrue); // 圖像反色顯示 0 否 1是,執行此命令后的所有操作均是按照設置顯示
extern void LCD_DisplayBMP_ST7565(const unsigned char *PicData); // 顯示BMP圖片
extern void LCD_setpos_ST7565(unsigned char Lx,unsigned char Ly); // 設置像素顯示坐標(x:0-127,y:0-7)
extern void LCD_Set_Place_ST7565(unsigned char x,unsigned char y);
extern void LCD_setCharpos_ST7565(unsigned char Lx,unsigned char Ly); // 設置字符位置(x:0-8,y:0-3)
extern void LCD_disp_printR_ST7565(unsigned char *s,unsigned char x,unsigned char y,u8 length); // display 中英文字符
extern void Write_Data_ST7565(unsigned char dat);
extern void LCD_7565_Power_ON(void);
extern void LCD_7565_Power_OFF(void);
#endif
#endif
復制代碼
作者:
hclin
時間:
2023-12-27 09:40
謝謝分享。如果能附上 L_ASCII_8x8.h ,讓 LCD_disp_printR_ST7565(Test",0,0,4);
LCD_disp_printR_ST7565(“2023/07/03",0,2,10);
能順利運行的話,就更完美了。
歡迎光臨 (http://www.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
粉嫩一区二区三区四区公司1
|
在线观看亚洲精品视频
|
亚洲精品66
|
国产欧美一级
|
91视频亚洲
|
天天色av
|
久久精品国产一区二区电影
|
日韩欧美中文字幕在线观看
|
www.亚洲一区二区三区
|
黄色一级视频
|
国产精品视频二区三区
|
91视频免费
|
精品成人佐山爱一区二区
|
一区二区在线不卡
|
国产精品一区二区视频
|
欧美11一13sex性hd
|
天堂色综合
|
九九av
|
综合一区二区三区
|
狠狠ri
|
国产又色又爽又黄又免费
|
亚洲精品在线免费观看视频
|
黄色一级大片在线免费看产
|
丁香色婷婷
|
色视频在线播放
|
日韩午夜一区二区三区
|
国产精品日韩
|
国产视频二区
|
国产一区三区在线
|
欧美精品一区二区在线观看
|
91午夜在线
|
亚洲欧美激情网
|
一本色道精品久久一区二区三区
|
国产精品亚洲一区
|
亚洲国产精品网站
|
欧美日韩亚洲一区
|
91精品国产91久久久久久
|
色视频在线播放
|
国产免费一区二区
|
欧美日韩在线观看视频
|
久久久精品
|