普通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
复制代码
|