液晶模组测试画面一般有全黑、全白、横线单、横线双、竖线单、竖线双、雪花、方框、字符、图形画面等。不同的公司当然会不一样。
1.字符型程序
16205
(原文件名:16205.JPG)
20200
(原文件名:20200.JPG)
40400
(原文件名:40400.JPG)
//*********--------09.03.01--------****
//********Character LCM screen test****
//********MICROTIPS TECHNDLOGY-----****
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define Data_Port P0
uchar code DATA[]={0xff,0xff,0xff,0x00,0x00,0xff,
0x55,0x55,0xaa,0xaa,0x55,0xaa,0xaa,0x55};
sbit RS=P2^0;
sbit RW=P2^1;
sbit EN=P2^2;
sbit NEXT=P1^3;
sbit LAST=P1^4;
sbit AUTO=P1^5;
uchar num,k;
uchar i,j;
void init();
void delay1ms(uint z);
void write_com(uchar com);
void write_data(uchar date);
void show();
void displaydata();
void displaydata1();
void key();
void main()
{
init();
show();
displaydata();// written characters Library function
while(1)
{
key();
}
}
void key()
{
if(NEXT==0) //The next screen
{
delay1ms(30);
if(NEXT==0)
{
k++;
if(k>11)
k=1;
while(!NEXT);
write_com(0x01);//Clean screen
show();
}
}
if(LAST==0) //The last screen
{
delay1ms(30);
if(LAST==0)
{
k--;
if(k<1)
k=11;
while(!LAST);
write_com(0x01);//Clean screen
show();
}
}
if(AUTO==0) //Automatically switch the screen
{
delay1ms(30);
if(AUTO==0)
{
delay1ms(30);
while(!AUTO);
write_com(0x01);//Clean screen
for(k=1;k<12;k++)
{
show();
delay1ms(2000);
}
}
}
}
void show()
{
switch(k)
{
case 1://Special characters
write_com(0x80);
for(num=0;num<40;num++)
write_data(0x41+num);
write_com(0x80+0x40);
for(num=0;num<40;num++)
write_data(0x61+num);
break;
case 2://All black
write_com(0x80);
for(i=0;i<40;i++) write_data(0x00);
write_com(0xc0);
for(i=0;i<40;i++) write_data(0x00);
break;
case 3:
write_com(0x80);//display first line
for(i=0;i<40;i++) write_data(0x07);
write_com(0xc0);//display scecond line
for(i=0;i<40;i++) write_data(0x07);
break;
case 4:
write_com(0x01);//All white
break;
case 5://Single Common line
write_com(0x80);
for(i=0;i<40;i++) write_data(0x01);
write_com(0xc0);
for(i=0;i<40;i++) write_data(0x01);
break;
case 6://Double Common line
write_com(0x80);
for(i=0;i<40;i++) write_data(0x02);
write_com(0xc0);
for(i=0;i<40;i++) write_data(0x02);
break;
case 7://Single Segment lines
write_com(0x80);
for(i=0;i<40;i++) write_data(0x03);
write_com(0xc0);
for(i=0;i<40;i++) write_data(0x03);
break;
case 8://Double Segment lines
write_com(0x80);
for(i=0;i<40;i++) write_data(0x04);
write_com(0xc0);
for(i=0;i<40;i++) write_data(0x04);
break;
case 9://Snowflake 1
write_com(0x80);
for(i=0;i<40;i++) write_data(0x05);
write_com(0xc0);
for(i=0;i<40;i++) write_data(0x05);
break;
case 10://Snowflake 2
write_com(0x80);
for(i=0;i<40;i++) write_data(0x06);
write_com(0xc0);
for(i=0;i<40;i++) write_data(0x06);
break;
case 11://Special characters
write_com(0x80);
for(num=0;num<40;num++)
write_data(0xb0+num);
write_com(0x80+0x40);
for(num=0;num<40;num++)
write_data(0xe0+num);
break;
}
}
void displaydata()
{
uchar i,j;
write_com(0x40);//set cgram
for(i=0;i<14;i+=2)
{
for(j=0;j<4;j++)
{
write_data(DATA
);
write_data(DATA[i+1]);
}
}
write_data(0xff);
write_data(0x11);
write_data(0x11);
write_data(0x11);
write_data(0x11);
write_data(0x11);
write_data(0x11);
write_data(0xff);
}
void init()//Initialization Functions
{
EN=0;
k=1;
write_com(0x38);//Set16*2,5*7,8-bit data interface
write_com(0x0c);//Open show,Don't show Cursor and Blinking cursor
write_com(0x06);//Automatic cursor 1,All screen display will not move
write_com(0x01);//Clean screen
}
void delay1ms(uint z)//delay 1ms Functions
{
uint x,y;
for(x=z;x>0;x--)
for(y=50;y>0;y--);
}
void write_com(uchar com)//Writing directive Functions
{
RS=0;
RW=0;
Data_Port=com;
delay1ms(1);
EN=1;//Give EN a high pulse
delay1ms(1);
EN=0;
}
void write_data(uchar date)//Write date function
{
RS=1;
RW=0;
Data_Port=date;
delay1ms(1);
EN=1;//Give EN a high pulse
delay1ms(1);
EN=0;
}
(原文件名:12864(KS108).JPG)
点击此处下载 ourdev_540015.zip(文件大小:854K) (原文件名:12864(KS0108).zip)
一周热门 更多>