求无字库12864液晶显示图像的51单片机程序,C语言版的 30
3个回答
展开全部
标准的一般都是这个程序
#include <reg52.h>
#include <math.h>
#define lcd_data P1
sbit cs1=P2^3;
sbit cs2=P2^4;
sbit di=P2^0;
sbit rw=P2^1;
sbit e=P2^2;
void delay(int t)
{
int i,j,k;
for(i=0;i<t;i++)
{ for(j=0;j<255;j++)
k++;}
}
void write_com_l(unsigned int command)
{
cs1=1;
rw=0;
di=0;
lcd_data=command;
e=1;
e=0;
cs1=0;
}
void write_data_l(unsigned int data0)
{
cs1=1;
rw=0;
di=1;
lcd_data=data0;
e=1;
e=0;
cs1=0;
}
void write_com_r(unsigned int command)
{
cs2=1;
rw=0;
di=0;
lcd_data=command;
e=1;
e=0;
cs2=0;
}
void write_data_r(unsigned int data0)
{
cs2=1;
rw=0;
di=1;
lcd_data=data0;
e=1;
e=0;
cs2=0;
}
void disp0()
{
unsigned int i,j;
for (i=0;i<8;i++)
{write_com_l(0xb8+i);
write_com_r(0xb8+i);
write_com_l(0x40);
write_com_r(0x40);
for (j=0;j<64;j++)
{write_data_l(0xaa);
write_data_r(0xaa);
}
}
}
void disp1()
{
unsigned int i,j;
for (i=0;i<8;i++)
{write_com_l(0xb8+i);
write_com_r(0xb8+i);
write_com_l(0x40);
write_com_r(0x40);
for (j=0;j<64;j++)
{write_data_l(0x55);
write_data_r(0x55);
}
}
}
void disp2()
{
unsigned int i,j;
for (i=0;i<8;i++)
{write_com_l(0xb8+i);
write_com_r(0xb8+i);
write_com_l(0x40);
write_com_r(0x40);
for (j=0;j<64;j++)
{write_data_l(0x0f);
write_data_r(0x0f);
}
}
}
void disp3()
{
unsigned int i,j;
for (i=0;i<8;i++)
{write_com_l(0xb8+i);
write_com_r(0xb8+i);
write_com_l(0x40);
write_com_r(0x40);
for (j=0;j<64;j++)
{write_data_l(0xf0);
write_data_r(0xf0);
}
}
}
void init_lcd() //初始化LCD清屏
{
write_com_l(0x3e);
write_com_r(0x3e);
write_com_l(0x3f);
write_com_r(0x3f);
write_com_l(0xc0);
write_com_r(0xc0);
write_com_l(0xb8);
write_com_r(0xb8);
write_com_l(0x40);
write_com_r(0x40);
for(;1;)
{
disp0();
delay(0x0ff);
disp1();
delay(0x0ff);
disp2();
delay(0x0ff);
disp3();
delay(0x0ff);
}
}
void main()
{
IE=0x81;
init_lcd();
}
void innt0 () interrupt 0
{
do {}while(1);
}
#include <reg52.h>
#include <math.h>
#define lcd_data P1
sbit cs1=P2^3;
sbit cs2=P2^4;
sbit di=P2^0;
sbit rw=P2^1;
sbit e=P2^2;
void delay(int t)
{
int i,j,k;
for(i=0;i<t;i++)
{ for(j=0;j<255;j++)
k++;}
}
void write_com_l(unsigned int command)
{
cs1=1;
rw=0;
di=0;
lcd_data=command;
e=1;
e=0;
cs1=0;
}
void write_data_l(unsigned int data0)
{
cs1=1;
rw=0;
di=1;
lcd_data=data0;
e=1;
e=0;
cs1=0;
}
void write_com_r(unsigned int command)
{
cs2=1;
rw=0;
di=0;
lcd_data=command;
e=1;
e=0;
cs2=0;
}
void write_data_r(unsigned int data0)
{
cs2=1;
rw=0;
di=1;
lcd_data=data0;
e=1;
e=0;
cs2=0;
}
void disp0()
{
unsigned int i,j;
for (i=0;i<8;i++)
{write_com_l(0xb8+i);
write_com_r(0xb8+i);
write_com_l(0x40);
write_com_r(0x40);
for (j=0;j<64;j++)
{write_data_l(0xaa);
write_data_r(0xaa);
}
}
}
void disp1()
{
unsigned int i,j;
for (i=0;i<8;i++)
{write_com_l(0xb8+i);
write_com_r(0xb8+i);
write_com_l(0x40);
write_com_r(0x40);
for (j=0;j<64;j++)
{write_data_l(0x55);
write_data_r(0x55);
}
}
}
void disp2()
{
unsigned int i,j;
for (i=0;i<8;i++)
{write_com_l(0xb8+i);
write_com_r(0xb8+i);
write_com_l(0x40);
write_com_r(0x40);
for (j=0;j<64;j++)
{write_data_l(0x0f);
write_data_r(0x0f);
}
}
}
void disp3()
{
unsigned int i,j;
for (i=0;i<8;i++)
{write_com_l(0xb8+i);
write_com_r(0xb8+i);
write_com_l(0x40);
write_com_r(0x40);
for (j=0;j<64;j++)
{write_data_l(0xf0);
write_data_r(0xf0);
}
}
}
void init_lcd() //初始化LCD清屏
{
write_com_l(0x3e);
write_com_r(0x3e);
write_com_l(0x3f);
write_com_r(0x3f);
write_com_l(0xc0);
write_com_r(0xc0);
write_com_l(0xb8);
write_com_r(0xb8);
write_com_l(0x40);
write_com_r(0x40);
for(;1;)
{
disp0();
delay(0x0ff);
disp1();
delay(0x0ff);
disp2();
delay(0x0ff);
disp3();
delay(0x0ff);
}
}
void main()
{
IE=0x81;
init_lcd();
}
void innt0 () interrupt 0
{
do {}while(1);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询