#include<KF8A100EOG.h>
//main Function
#define uchar unsigned char
#define uint unsigned int
#define sda P1LR3
#define scl P1LR5
#define reset P0LR4
char code CGRAM_code[]={
0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,
0x1f,0x11,0x11,0x11,0x11,0x11,0x11,0x1f,
0x1f,0x00,0x1f,0x00,0x1f,0x00,0x1f,0x00,
0x00,0x1f,0x00,0x1f,0x00,0x1f,0x00,0x1f,
0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,
0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
0x0f,0x09,0x0f,0x09,0x0f,0x09,0x11,0x00,
0x08,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02,
};
char code CGRAM[]=
{0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
/*长一点的延时*/
void delay(int i)
{
int j,k;
for(j=0;j<i;j++)
for(k=0;k<110;k++);
}
/*短一点的延时*/
void delay1(int i)
{
int j,k;
for(j=0;j<i;j++)
for(k=0;k<1;k++);
}
void start_flag()
{
scl=1; /*START FLAG*/
sda=1; /*START FLAG*/
delay1(5);
sda=0; /*START FLAG*/
delay1(5);
scl=0;
delay1(5);
}
void stop_flag()
{
scl=1; /*STOP FLAG*/
delay1(5);
sda=0; /*STOP FLAG*/
delay1(5);
sda=1; /*STOP FLAG*/
delay1(5);
}
void Init_mcu()
{
OSCCTL=0x60;//时钟配置为16M
//TR1=0x28;//P13、P15配置为输入,IIC口必须设置为输入模式
TR13=0;
TR15=0;
P1LR3=0;
P1LR5=0;
}
void transfer(uchar data1)
{
int i;
for(i=0;i<8;i++)
{
scl=0;
if(data1&0x80)
{ sda=1; }
else
{ sda=0; }
scl=1;
delay1(2);
scl=1;
data1=data1<<1;
}
sda=0;
scl=1;
delay1(2);
scl=0;
}
void write_cmd(uchar com)//写命令
{
start_flag();
transfer(0x7c);
transfer(0x80);
transfer(com);
stop_flag();
}
//写数据到 OLED 显示模块
void transfer_data(uchar dat)
{
start_flag();
transfer(0x7c);
transfer(0x40);
transfer(dat);
stop_flag();
}
/*初始化 LCD MODULE*/
void initial_lcd()
{
reset =0;
delay(20);
reset =1;
write_cmd(0x38); /*设置2x16行*/
delay(10);
write_cmd(0x01); /*清除显示*/
delay(5);
write_cmd(0x06); /*设置显示方式 */
delay(5);
write_cmd(0x0c); /*开显示,开光标,光标闪烁*/
delay(5);
write_cmd(0x39); /*extension instruction*/
write_cmd(0x1c); //
delay(5);
write_cmd(0x69); //
delay(5);
write_cmd(0x57); //粗调对比度,范围 0x54-0x57
delay(5);
write_cmd(0x7a); //微调对比度,范围 0x70-0x7f
delay(5);
}
void write_CGRAM()
{
int i;
write_cmd(0x38); /*extension instruction扩展指令*/
write_cmd(0x40); //set position设定位置
for(i=0;i<64;i++)
{
transfer_data(CGRAM_code[i]);
}
}
/*在指定行和列位置显示指定的字母、数字(5*7 点阵的)*/
void disp_char(int line,int column,char code *dp)
{
int i;
write_cmd(0x80+(line-1)*0x40+(column-1)); //set position
for(i=0;i<16;i++)
{
transfer_data(*dp);
dp++;
}
}
/*在指定行和列位置显示指定的字母、数字(5*7 点阵的)*/
void disp_CGRAM()
{
int i,j;
for(j=0;j<8;j++)
{
write_cmd(0x80); //set position
for(i=0;i<16;i++)
{
transfer_data(CGRAM[j]);
}
write_cmd(0xc0); //set position
for(i=0;i<16;i++)
{
transfer_data(CGRAM[j]);
}
}
}
void main()
{
Init_mcu();
initial_lcd();
write_CGRAM();
while(1)
{
{
disp_char(1,1,"**JLX1602G-391**"); /*在第 1 行,第 1 列,显示字符。。。。*/
disp_char(2,1,"*Character COG**"); /*在第 2 行,第 1 列,显示字符。。。。*/
delay(300);
disp_char(1,1,"jlxlcd 1602g-391"); /*在第 1 行,第 1 列,显示字符。。。。*/
disp_char(2,1,"*2015/08/17 cog**"); /*在第 2 行,第 1 列,显示字符。。。。*/
delay(300);
disp_char(1,1,"*0123456789 123*"); /*在第 1 行,第 1 列,显示字符。。。。*/
disp_char(2,1,"*Character COg**"); /*在第 2 行,第 1 列,显示字符。。。。*/
delay(300);
disp_char(1,1,"*xxxxxxxxxxxxxx*"); /*在第 1 行,第 1 列,显示字符。。。。*/
disp_char(2,1,"*cccccccccccccc*"); /*在第 2 行,第 1 列,显示字符。。。。*/
delay(300);
disp_CGRAM();
delay(300);
}
}
}
|
请问楼主问题解决了吗 ,我想参考一下