2525 views|1 replies
- Last login
- 2022-12-8
- Online Time
- 26 hours
- Prestige
- 32 points
- Points
- 0 points
|
Share LCD JLX12864G-086 driver based on msp430
[Copy link]
C file: #include
#include "delay.h"
void JLX12864G_086_GPIOInit(void)
{
LCD_SCLK_Init;
LCD_SID_Init;
LCD_RS_Init;
LCD_RESET_Init;
LCD_CS1_Init;
ROM_IN_Init;
ROM_OUT_Init;
ROM_SCK_Init;
ROM_CS_Init;
}
void transfer_command_lcd(u8 data1)
{
char i;
LCD_CS1_LOW;
LCD_RS_LOW;
for(i=0;i<8;i++)
{
LCD_SCLK_LOW;
if(data1&0x80)
LCD_SID_HIGH;
else
LCD_SID_LOW;
LCD_SCLK_HIGH;
data1=data1<<1;
}
LCD_CS1_HIGH;
}
void initial_lcd(void)
{
LCD_RESET_LOW;
Delay_us(100);
LCD_RESET_HIGH;
Delay_us(100);
transfer_command_lcd(0xe2); //软复位
Delay_us(5);
transfer_command_lcd(0x2c); //升压步聚1
Delay_us(50);
transfer_command_lcd(0x2e); //升压步聚2
Delay_us(50);
transfer_command_lcd(0x2f); //升压步聚3
Delay_us(5);
transfer_command_lcd(0x23); //粗调对比度,可设置范围0x20~0x27
transfer_command_lcd(0x81); //微调对比度
transfer_command_lcd(0x28); //微调对比度的值,可设置范围0x00~0x3f
transfer_command_lcd(0xa2); //1/9偏压比(bias)
transfer_command_lcd(0xc8); //行扫描顺序:从上到下
transfer_command_lcd(0xa0); //列扫描顺序:从左到右
transfer_command_lcd(0x40); //起始行:第一行开始
transfer_command_lcd(0xaf); //开显示
}
void clear_screen(void)
{
unsigned char i,j;
for(i=0;i<8;i++)
{
transfer_command_lcd(0xb0+i);
transfer_command_lcd(0x10);
transfer_command_lcd(0x00);
for(j=0;j<128;j++)
{
transfer_data_lcd(0x00);
}
}
}
void transfer_data_lcd(u8 data1)
{
char i;
LCD_CS1_LOW;
LCD_RS_HIGH;
for(i=0;i<8;i++)
{
LCD_SCLK_LOW;
if(data1&0x80) LCD_SID_HIGH;
else LCD_SID_LOW;
LCD_SCLK_HIGH;
data1=data1<<=1;
}
LCD_CS1_HIGH;
}
void lcd_address(u16 page,u16 column)
{
column=column-0x01;
transfer_command_lcd(0xb0+page-1);
transfer_command_lcd(0x10+(column>>4&0x0f));
transfer_command_lcd(column&0x0f);
}
void display_128x64(u8 *dp)
{
uint i,j;
for(j=0;j<8;j++)
{
lcd_address(j+1,1);
for (i=0;i<128;i++)
{
transfer_data_lcd(*dp);
dp++;
}
}
}
void display_graphic_16x16(uchar page,uchar column,uchar *dp)
{
uint i,j;
for(j=0;j<2;j++)
{
lcd_address(page+j,column);
for (i=0;i<16;i++)
{
transfer_data_lcd(*dp);
dp++;
}
}
}
void display_graphic_8x16(uchar page,uchar column,uchar *dp)
{
uint i,j;
for(j=0;j<2;j++)
{
lcd_address(page+j,column);
for (i=0;i<8;i++)
{
transfer_data_lcd(*dp);
dp++;
}
}
}
void display_graphic_5x8(uchar page,uchar column,uchar *dp)
{
uint i;
lcd_address(page,column);
for (i=0;i<5;i++)
{
transfer_data_lcd(*dp);
dp++;
}
}
void send_command_to_ROM(uchar datu ) //送指令到字库
{
uchar i;
for(i=0;i<8;i++ )
{
ROM_SCK_LOW;
Delay_us(10);
if(datu & 0x80)
ROM_IN_HIGH;
else
ROM_IN_LOW;
datu = datu<<1;
ROM_SCK_HIGH;
Delay_us(10);
}
}
static uchar get_data_from_ROM( ) //从字库取汉字或字符
{
uchar i;
uchar ret_data=0;
for(i=0;i<8;i++)
{
ROM_OUT_HIGH;
ROM_SCK_LOW;
//delay_us(1);
ret_data=ret_data<<1;
if((ROM_OUT_IN) == ROM_OUT_BIT)
ret_data = ret_data+1;
else
ret_data = ret_data;
ROM_SCK_HIGH;
//delay_us(1);
}
return(ret_data);
}
void get_and_write_16x16(u32 fontaddr,uchar page,uchar column)
{
uchar i,j,disp_data;
ROM_CS_LOW;
send_command_to_ROM(0x03);
send_command_to_ROM((fontaddr&0xff0000)>>16);
send_command_to_ROM((fontaddr&0xff00)>>8);
send_command_to_ROM(fontaddr&0xff);
for(j=0;j<2;j++)
{
lcd_address(page+j,column);
for(i=0; i<16; i++ )
{
disp_data=get_data_from_ROM();
transfer_data_lcd(disp_data);
}
}
ROM_CS_HIGH;
}
void get_and_write_8x16(u32 fontaddr,uchar page,uchar column)
{
uchar i,j,disp_data;
ROM_CS_LOW;
send_command_to_ROM(0x03);
send_command_to_ROM((fontaddr&0xff0000)>>16);
send_command_to_ROM((fontaddr&0xff00)>>8);
send_command_to_ROM(fontaddr&0xff);
for(j=0;j<2;j++)
{
lcd_address(page+j,column);
for(i=0; i<8; i++ )
{
disp_data=get_data_from_ROM();
transfer_data_lcd(disp_data);
}
}
ROM_CS_HIGH;
}
void get_and_write_5x8(u32 fontaddr,uchar page,uchar column)
{
uchar i,disp_data;
ROM_CS_LOW;
send_command_to_ROM(0x03);
send_command_to_ROM((fontaddr&0xff0000)>>16);
send_command_to_ROM((fontaddr&0xff00)>>8);
send_command_to_ROM(fontaddr&0xff);
lcd_address(page,column);
for(i=0; i<5; i++ )
{
disp_data=get_data_from_ROM();
transfer_data_lcd(disp_data);
}
ROM_CS_HIGH;
}
u32 fontaddr=0;
void display_GB2312_string(uchar page,uchar column,uchar *text)
{
uchar i= 0;
while((text[i]>0x00))
{
if(((text[i]>=0xb0) &&(text[i]<=0xf7))&&(text[i+1]>=0xa1))
{
fontaddr = (text[i]- 0xb0)*94;
fontaddr += (text[i+1]-0xa1)+846;
fontaddr = (u32)(fontaddr*32);
get_and_write_16x16(fontaddr,page,column);
i+=2;
column+=16;
}
else if(((text[i]>=0xa1) &&(text[i]<=0xa3))&&(text[i+1]>=0xa1))
{
fontaddr = (text[i]- 0xa1)*94;
fontaddr += (text[i+1]-0xa1);
fontaddr = (u32)(fontaddr*32);
get_and_write_16x16(fontaddr,page,column);
i+=2;
column+=16;
}
else if((text[i]>=0x20) &&(text[i]<=0x7e))
{
fontaddr = (text[i]- 0x20);
fontaddr = (unsigned long)(fontaddr*16);
fontaddr = (unsigned long)(fontaddr+0x3cf80);
get_and_write_8x16(fontaddr,page,column);
i+=1;
column+=8;
}
else
i++;
}
}
void display_string_5x8(uchar page,uchar column,uchar *text)
{
unsigned char i= 0;
while((text[i]>0x00))
{
if((text[i]>=0x20) &&(text[i]<=0x7e))
{
fontaddr = (text[i]- 0x20);
fontaddr = (unsigned long)(fontaddr*8);
fontaddr = (unsigned long)(fontaddr+0x3bfc0);
get_and_write_5x8(fontaddr,page,column);
i+=1;
column+=6;
}
else
i++;
}
}
H文件:
#ifndef JLX12864G_086_H_
#define JLX12864G_086_H_
#include "msp430f5529.h"
#if 1
#define LCD_CS1_PORT P3DIR
#define LCD_CS1_OUT P3OUT
#define LCD_CS1_BIT BIT3
#define LCD_RESET_PORT P4DIR
#define LCD_RESET_OUT P4OUT
#define LCD_RESET_BIT BIT6
#define LCD_RS_PORT P4DIR
#define LCD_RS_OUT P4OUT
#define LCD_RS_BIT BIT7
#define LCD_SID_PORT P5DIR
#define LCD_SID_OUT P5OUT
#define LCD_SID_BIT BIT6
#define LCD_SCLK_PORT P5DIR
#define LCD_SCLK_OUT P5OUT
#define LCD_SCLK_BIT BIT7
#define ROM_CS_PORT P7DIR
#define ROM_CS_OUT P7OUT
#define ROM_CS_BIT BIT4
#define ROM_SCK_PORT P7DIR
#define ROM_SCK_OUT P7OUT
#define ROM_SCK_BIT BIT5
#define ROM_OUT_PORT P7DIR
#define ROM_OUT_OUT P7OUT
#define ROM_OUT_BIT BIT6
#define ROM_OUT_IN P7IN&BIT6
#define ROM_IN_PORT P7DIR
#define ROM_IN_OUT P7OUT
#define ROM_IN_BIT BIT7
#else
#define LCD_SCLK_PORT P2DIR
#define LCD_SCLK_OUT P2OUT
#define LCD_SCLK_BIT BIT5
#define LCD_SID_PORT P2DIR
#define LCD_SID_OUT P2OUT
#define LCD_SID_BIT BIT4
#define LCD_RS_PORT P1DIR
#define LCD_RS_OUT P1OUT
#define LCD_RS_BIT BIT5
#define LCD_RESET_PORT P1DIR
#define LCD_RESET_OUT P1OUT
#define LCD_RESET_BIT BIT4
#define LCD_CS1_PORT P1DIR
#define LCD_CS1_OUT P1OUT
#define LCD_CS1_BIT BIT3
#define ROM_IN_PORT P1DIR
#define ROM_IN_OUT P1OUT
#define ROM_IN_BIT BIT2
#define ROM_OUT_PORT P4DIR
#define ROM_OUT_OUT P4OUT
#define ROM_OUT_BIT BIT3
#define ROM_OUT_IN P4IN & BIT3
#define ROM_SCK_PORT P4DIR
#define ROM_SCK_OUT P4OUT
#define ROM_SCK_BIT BIT0
#define ROM_CS_PORT P3DIR
#define ROM_CS_OUT P3OUT
#define ROM_CS_BIT BIT7
#endif
#define LCD_SCLK_Init LCD_SCLK_PORT |= LCD_SCLK_BIT
#define LCD_SCLK_HIGH LCD_SCLK_OUT |= LCD_SCLK_BIT
#define LCD_SCLK_LOW LCD_SCLK_OUT &=~ LCD_SCLK_BIT
#define LCD_SID_Init LCD_SID_PORT |= LCD_SID_BIT
#define LCD_SID_HIGH LCD_SID_OUT |= LCD_SID_BIT
#define LCD_SID_LOW LCD_SID_OUT &=~ LCD_SID_BIT
#define LCD_RS_Init LCD_RS_PORT |= LCD_RS_BIT
#define LCD_RS_HIGH LCD_RS_OUT |= LCD_RS_BIT
#define LCD_RS_LOW LCD_RS_OUT &=~ LCD_RS_BIT
#define LCD_RESET_Init LCD_RESET_PORT |= LCD_RESET_BIT
#define LCD_RESET_HIGH LCD_RESET_OUT |= LCD_RESET_BIT
#define LCD_RESET_LOW LCD_RESET_OUT &=~ LCD_RESET_BIT
#define LCD_CS1_Init LCD_CS1_PORT |= LCD_CS1_BIT
#define LCD_CS1_HIGH LCD_CS1_OUT |= LCD_CS1_BIT
#define LCD_CS1_LOW LCD_CS1_OUT &=~ LCD_CS1_BIT
#define ROM_IN_Init ROM_IN_PORT |= ROM_IN_BIT
#define ROM_IN_HIGH ROM_IN_OUT |= ROM_IN_BIT
#define ROM_IN_LOW ROM_IN_OUT &=~ ROM_IN_BIT
#define ROM_OUT_Init ROM_OUT_PORT &=~ ROM_OUT_BIT
#define ROM_OUT_HIGH ROM_OUT_OUT |= ROM_OUT_BIT
#define ROM_OUT_LOW ROM_OUT_OUT &=~ ROM_OUT_BIT
#define ROM_SCK_Init ROM_SCK_PORT |= ROM_SCK_BIT
#define ROM_SCK_HIGH ROM_SCK_OUT |= ROM_SCK_BIT
#define ROM_SCK_LOW ROM_SCK_OUT &=~ ROM_SCK_BIT
#define ROM_CS_Init ROM_CS_PORT |= ROM_CS_BIT
#define ROM_CS_HIGH ROM_CS_OUT |= ROM_CS_BIT
#define ROM_CS_LOW ROM_CS_OUT &=~ ROM_CS_BIT
void JLX12864G_086_GPIOInit(void);
void transfer_command_lcd(u8 data1);
void initial_lcd(void);
void clear_screen(void);
void transfer_data_lcd(u8 data1);
void lcd_address(u16 page,u16 column);
void display_128x64(u8 *dp);
void display_graphic_16x16(uchar page,uchar column,uchar *dp);
void display_graphic_8x16(uchar page,uchar column,uchar *dp);
void display_graphic_5x8(uchar page,uchar column,uchar *dp);
void send_command_to_ROM(uchar datu); //送指令到字库
static uchar get_data_from_ROM();
void get_and_write_16x16(u32 fontaddr,uchar page,uchar column);
void get_and_write_8x16(u32 fontaddr,uchar page,uchar column);
void get_and_write_5x8(u32 fontaddr,u8 page,u8 column);
void display_GB2312_string(uchar page,uchar column,uchar *text);
void display_string_5x8(uchar page,uchar column,uchar *text);
#endif /* 12864G_086_H_ */
|
|