分享下JLX高性价比的液晶的驱动程序,这款是模拟IIC驱动的,操作很方便
单片机源程序如下:
- /* 液晶模块型号:JLX128128G-610-PN-IIC
- I2C接口
- 驱动IC是:ST7571
- //单片机:STM32F103RBT6
- */
- #include <stm32f10x_lib.h>
- #include <sys.h>
- #include <delay.h>
- #include <JLX128128G_610_PN_IIC.h>
- #include <chinese_code.h>
- #include <image.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define ulong unsigned long
- //等待按键,3个按键,有任何一个按键按下都可以进入下一步
- void waitkey(void)
- {
- repeat:
- if(key2==1&&key3==1&&key4==1) goto repeat;
- else delay_ms(600);
- }
- void transfer(int data1)
- {
- int i;
- for(i=0;i<8;i++)
- {
- LCD_SCL=0;
- if(data1&0x80) LCD_SDA=1;
- else LCD_SDA=0;
- LCD_SCL=1;
- LCD_SCL=0;
- data1=data1<<1;
- }
- LCD_SDA=0;
- LCD_SCL=1;
- LCD_SCL=0;
- }
- void start_flag()
- {
- LCD_SCL=1; /*START FLAG*/
- LCD_SDA=1; /*START FLAG*/
- LCD_SDA=0; /*START FLAG*/
- }
- void stop_flag()
- {
- LCD_SCL=1; /*STOP FLAG*/
- LCD_SDA=0; /*STOP FLAG*/
- LCD_SDA=1; /*STOP FLAG*/
- }
- //写命令到液晶显示模块
- void transfer_command(uchar com)
- {
- start_flag();
- transfer(0x78);
- transfer(0x80);
- transfer(com);
- stop_flag();
- }
- //写数据到液晶显示模块
- void transfer_data(uchar dat)
- {
- start_flag();
- transfer(0x78);
- transfer(0xC0);
- transfer(dat);
- stop_flag();
- }
- void initial_lcd()
- {
- LCD_RST=0;
- delay_ms(1);
- LCD_RST=1;
- delay_ms(10);
- transfer_command(0x2c);
- delay_ms(200);
- transfer_command(0x2e);
- delay_ms(200);
- transfer_command(0x2f);
- delay_ms(10);
-
- transfer_command(0xae); //显示关
- transfer_command(0x38); //模式设置
- transfer_command(0xb8); //85HZ
- transfer_command(0xc8); //行扫描顺序
- transfer_command(0xa0); //列扫描顺序
-
- transfer_command(0x44); //Set initial COM0 register
- transfer_command(0x00);
- transfer_command(0x40); //Set initial display line register
- transfer_command(0x00);
- transfer_command(0xab);
- transfer_command(0x67);
- transfer_command(0x27); //粗调对比度,可设置范围0x20~0x27
- transfer_command(0x81); //微调对比度
- transfer_command(0x28); //微调对比度的值,可设置范围0x00~0x3f
- transfer_command(0x56); //0x56 1/11 bias
- transfer_command(0xf3);
- transfer_command(0x04);
- transfer_command(0x93);
-
- transfer_command(0xaf); //显示开
- }
- void lcd_address(uchar page,uchar column)
- {
- column=column;
- page=page-1;
- transfer_command(0xb0+page);
- transfer_command(((column>>4)&0x0f)+0x10);
- transfer_command(column&0x0f);
- }
- void clear_screen()
- {
- uchar i,j;
- for(j=0;j<16;j++)
- {
- lcd_address(j+1,0);
- for(i=0;i<128;i++)
- {
- transfer_data(0x00);
- transfer_data(0x00);
- }
- }
- }
- //显示8x16的点阵的字符串,括号里的参数分别为(页,列,字符串指针)
- void display_string_8x16(u8 page,u8 column,u8*text)
- {
- u8 i=0,j,k,n;
- while(text[i]>0x00)
- {
- if((text[i]>=0x20)&&(text[i]<=0x7e))
- {
- j=text[i]-0x20;
- for(n=0;n<2;n++)
- {
- lcd_address(page+n,column);
- for(k=0;k<8;k++)
- {
- transfer_data(ascii_table_8x16[j][k+8*n]);
- transfer_data(ascii_table_8x16[j][k+8*n]);
- }
- }
- i++;
- column+=8;
- }
- else
- i++;
-
- if(column>127)
- {
- column=0;
- page+=2;
- }
- }
- }
- //写入一组16x16点阵的汉字字符串(字符串表格中需含有此字)
- //括号里的参数:(页,列,汉字字符串)
- void display_string_16x16(u8 page,u8 column,u8 *text)
- {
- u8 i,j,k;
- u16 address;
- j = 0;
- while(text[j] != '\0')
- {
- i=0;
- address=1;
- while(Chinese_text_16x16[i]> 0x7e )
- {
- if(Chinese_text_16x16[i] == text[j])
- {
- if(Chinese_text_16x16[i+1] == text[j+1])
- {
- address = i*16;
- break;
- }
- }
- i +=2;
- }
- if(column>127)
- {
- column =0;
- page +=2;
- }
- if(address !=1)
- {
- for(k=0;k<2;k++)
- {
- lcd_address(page+k,column);
- for(i=0;i<16;i++)
- {
- transfer_data(Chinese_code_16x16[address]);
- transfer_data(Chinese_code_16x16[address]);
- address++;
- }
- }
- j +=2;
- }
- else
- {
- for(k=0;k<2;k++)
- {
- lcd_address(page+k,column);
- for(i=0;i<16;i++)
- {
- transfer_data(0x00);
- transfer_data(0x00);
- }
- }
- j++;
- }
- column +=16;
- }
- }
- //显示16x16点阵的汉字或者ASCII码8x16点阵的字符混合字符串
- //括号里的参数:(页,列,字符串)
- void display_string_8x16_16x16(u8 page,u8 column,u8 *text)
- {
- u8 temp[3];
- u16 i=0;
- while(text[i] !='\0')
- {
- if(text[i]>0x7e)
- {
- temp[0]=text[i];
- temp[1]=text[i+1];
- temp[2]='\0'; //汉字为两个字节
- display_string_16x16(page,column,temp); //显示汉字
- column +=16;
- i +=2;
- if(column>127)
- {
- column =0;
- page +=2;
- }
- }
- else
- {
- temp[0]=text[i];
- temp[1]='\0'; //字母占一个字节
- display_string_8x16(page,column,temp); //显示字母
- column +=8;
- i++;
- if(column>127)
- {
- column =0;
- page +=2;
- }
- }
- }
- }
- void display_32x32(u8 page,u8 column,u8 *dp)
- {
- u8 i,j;
- for(j=0;j<4;j++)
- {
- lcd_address(page+j,column);
- for(i=0;i<32;i++)
- {
- transfer_data(*dp);
- transfer_data(*dp);
- dp++;
- }
- }
- }
- void display_graphic(u8 *dp)
- {
- u8 i,j;
- for(j=0;j<16;j++)
- {
- lcd_address(j+1,0);
- for(i=0;i<128;i++)
- {
- transfer_data(*dp);
- transfer_data(*dp);
- dp++;
- }
- }
- }
- //==========主程序==========================================
- int main(void)
- {
- Stm32_Clock_Init(9); //8MHZ*9倍频=72MHz
- delay_init(72); //72MHz
- MCU_Port_initial();
- initial_lcd();
- while(1)
- {
- clear_screen();
- display_graphic(bmp2);
- waitkey();
- clear_screen();
- display_32x32(1,16,jing32);
- display_32x32(1,48,lian32);
- display_32x32(1,80,xun32);
- display_string_16x16(5,1,"深圳市晶联讯电子有限公司是集研发、生产、销售于一体的从事液晶显示屏及液晶显示模块的高科技公司。");
- waitkey();
- clear_screen();
- display_string_8x16(1,1,"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&()*+-,-./:;<=>?@[\]^_^{|}~0123456789ABCDFGHIJKLMNOPQRSTUVWXYZ");
- waitkey();
- clear_screen();
- display_string_8x16_16x16(1,1,"深圳市晶联讯电子 JLX128128G-610 128x128点阵 视区:59.4x59.4mm带16x16点阵中文 字库,或8x16或5x7点阵ASCII码,四灰度级显示功能。");
- waitkey();
- }
- }
复制代码
所有资料51hei提供下载:
128128改库函数版本.rar
(304.32 KB, 下载次数: 168)
JLX128128G-610-PN-IIC-STM32.7z
(148.29 KB, 下载次数: 116)
|