#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=0i<ti++)
{ for(j=0j<255j++)
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=0i<8i++)
{write_com_l(0xb8+i)
write_com_r(0xb8+i)
write_com_l(0x40)
write_com_r(0x40)
for (j=0j<64j++)
{write_data_l(0xaa)
write_data_r(0xaa)
}
}
}
void disp1()
{
unsigned int i,j
for (i=0i<8i++)
{write_com_l(0xb8+i)
write_com_r(0xb8+i)
write_com_l(0x40)
write_com_r(0x40)
for (j=0j<64j++)
{write_data_l(0x55)
write_data_r(0x55)
}
}
}
void disp2()
{
unsigned int i,j
for (i=0i<8i++)
{write_com_l(0xb8+i)
write_com_r(0xb8+i)
write_com_l(0x40)
write_com_r(0x40)
for (j=0j<64j++)
{write_data_l(0x0f)
write_data_r(0x0f)
}
}
}
void disp3()
{
unsigned int i,j
for (i=0i<8i++)
{write_com_l(0xb8+i)
write_com_r(0xb8+i)
write_com_l(0x40)
write_com_r(0x40)
for (j=0j<64j++)
{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)
}
/***12864并行接口参考程序,控制器st7920*/#include <reg51.h>
#include <intrins.h>
sbit RS = P3^0
sbit RW = P3^3
sbit E = P3^4
sbit PSB = P3^1 //串并口选择
sbit RES = P3^5
#define FIRST_ADDR 0 //定义字符/汉字显示起始位置
//延时子程序
void delay(unsigned int t)
{ unsigned int i,j
for(i=0i<ti++)
for(j=0j<10j++)
}
//测忙
void chk_busy()
{ RS=0
RW=1
E=1
while((P1&0x80)==0x80)
E=0
}
//读数据
unsigned char lcdrd()
{ unsigned char i
P3=0xFB
_nop_()
E=1
delay(5)
i=P1
_nop_()
E=0
return i
}
//写数据
void lcdwd(unsigned char dispdata)
{ chk_busy()
_nop_()
RS=1
RW=0
E=1
P1=dispdata
delay(5)
_nop_()
E=0
_nop_()
P1=0xff
}
//写指令代码
void lcdwc(unsigned char cmdcode)
{ chk_busy()
_nop_()
RS=0
RW=0
E=1
P1=cmdcode
delay(5)
_nop_()
E=0
_nop_()
P1=0xff
}
//初始化
void lcdreset()
{ delay(2000)
lcdwc(0x30) //选择基本指令集
lcdwc(0x30) //选择8bit数据流
delay(5)
lcdwc(0x0c) //开显示(无游标、不反白)
delay(5)
lcdwc(0x01) //清除显示,并且设定地址指针为00H
delay(5)
lcdwc(0x06) //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位
}
void hzkdis(unsigned char code *s)
{ while(*s>0)
{ lcdwd(*s)
s++
delay(500)
}
}
void hzklib()
{ lcdwc(0x80+FIRST_ADDR)
hzkdis("少小离家老大回,")
lcdwc(0x90+FIRST_ADDR)
hzkdis("乡音无改鬓毛衰。")
lcdwc(0x88+FIRST_ADDR)
hzkdis("儿童相见不相识,")
lcdwc(0x98+FIRST_ADDR)
hzkdis("笑问客从何处来。")
}
//整屏显示
//当ii=0时显示上面128×32
//当ii=8时显示下面128×32
void lcdfill(unsigned char disdata)
{ unsigned char x,y,ii
for(ii=0ii<9ii+=8)
for(y=0y<0x20y++)
for(x=0x<8x++)
{ lcdwc(0x36)
lcdwc(y+0x80) //行地址
lcdwc(x+0x80+ii)//列地址
lcdwc(0x30)
lcdwd(disdata)
lcdwd(disdata)
}
}
//当ii=0时显示上面128×32
//当ii=8时显示下面128×32
void lcdfill_upright(unsigned char disdata)
{ unsigned char x,y,ii
unsigned char i,f,k
for(ii=0ii<9ii+=8)
for(y=0y<4y++)
{ f=disdata
for(i=0i<8i++)
{ if((f&1)==1)
k=0xff
else
k=0
for(x=0x<8x++)
{ lcdwc(0x36)
lcdwc(y*8+i+0x80)
lcdwc(x+0x80+ii)
lcdwc(0x30)
lcdwd(k)
lcdwd(k)
}
f>>=1
}
}
}
main()
{ unsigned char i
i=0x55
RES=0
_nop_()
RES=1
while(1)
{ PSB=1
RW=0
lcdreset() //初始化LCD屏
lcdwc(0x01)
delay(1000)
lcdfill(0xff)
delay(6000)
lcdfill(i) //显示竖条
delay(6000)
lcdfill_upright(i) //显示横条
delay(6000)
lcdfill(0)
lcdwc(0x01)
delay(1000)
hzklib()
delay(4000)
i=~i
}
}
问题有多种,一、对比度是否调好(即是否有硬件问题)
二、void
WriteData(uchar
Data)
{
EN=0/*使能端*/
RS=1/*根据时序图拉低,选择写指令*/
RW=0/*根据时序图拉低,选择写模式*/
P0=Data/*命令数据准备*/
delay(0)
此处延时(省略判忙)
EN=1/*使能端跳变*/
EN=0/*使能端再次跳变*/
}
三、确认你的初始化没有问题
四、你的模块是否带字库
五、
我推测你这个程序最可能出现的问题v
void
display(uchar
show[])
{
delay(1)
WriteData()
}
此处未写任何数据
如有不明白Q
451526010
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)