串行12864&STM32程序
文档说明:此程序是从串行12864LCD的51程序中改写过来的。另:此程序是基于STM32f103内核芯片开发的,使用的屏幕为JLX12864G-086串行LCD。
/*********lcd12864.h**********/
/*********lcd12864.c**********/ #include \
/*其中SDA、SCK、RS、CS、RST已在头文件中宏定义*/
/*LCD_GPIO Init*/ void GPIO_LCD(void) { GPIO_InitTypeDefGPIO_InitStructure; GPIO_InitStructure.GPIO_Pin =SDA; //SDA GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIO_SDA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin =SCK; //SCK GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIO_SCK, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin =RST; //RST GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIO_RST, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin =RS; //RS GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIO_RS, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin =CS; //CS GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIO_CS, &GPIO_InitStructure);
}
/*write command to LCD*/
voidwrite_command(unsigned short int command) { unsigned short int i; CS_L; //开启片选(低电平有效) RS_L; //开启寄存器地址 for(i=0;i<8;i++) { SCK_L; //拉高时钟线——同SPI原理差不多 if(command&0x80) //传输指令 { SDA_H; } else { SDA_L; } SCK_H; //LCD读取指令 command = command << 1 ; } CS_H; //关闭片选 }
/*write data to LCD*/
voidwrite_data(unsigned short int data) { unsigned short int i; CS_L; RS_H; //开启数据地址 for(i=0;i<8;i++) { SCK_L; if(data&0x80) { SDA_H; } else {
SDA_L; } SCK_H; data = data << 1 ; } CS_H; }
/* LCD Init */ voidlcd_Init(void) { GPIO_LCD(); //LCD管脚配置初始化 CS_L; //开启片选 RST_L; //LCD复位(低电平) delay_ms(22); RST_H; delay_ms(5); write_command(0xe2); //软件复位 delay_ms(2); write_command(0x2c); //内部升压 delay_ms(2); write_command(0x2e); //电压调整电路 delay_ms(2); write_command(0x2f); //电压跟随 delay_ms(2); write_command(0x23); //粗调对比度 write_command(0x81); //细调对比度(不改) write_command(0x28); //细调对比度 write_command(0xa2); // write_command(0xc8); // write_command(0xa0); // write_command(0x40); // write_command(0xaf); // }
/* LCD address */
voidlcd_address(unsigned short intpage,unsigned short int column) { CS_L;
column = column-1; page = page-1; write_command(0xb0+page); write_command(((column>>4)&0x0f)+0x10); write_command(column&0x0f); }
/*clear screen*/
voidclear_screen(void) { unsigned short inti,j; CS_L; for(i=0;i<9;i++) { lcd_address(i+1,1); for(j=0;j<128;j++) { write_data(0x00); } } CS_H; }
/*dispay a 128*64 picture*/
voidfull_display(unsigned short int *dp) { unsigned short inti,j; for(i=0;i<9;i++) { CS_L; lcd_address(i+1,1); for(j=0;j<128;j++) { write_data(*dp); dp++; } } }