新手请求大神,我写的12864DDRAM的打点函数哪里错了,感谢万分!
时间:10-02
整理:3721RD
点击:
这是我写的12864DDRAM的程序,打同PAGE同列的点的时候新的点会把旧的点覆盖,我用读数据函数读出来之前的数据再并上现在要打的点的数据不知道为什么也没有用。求大神帮忙T T
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define LCDLCDDisp_Off 0x3e
#define LCDLCDDisp_On 0x3f
#define Page_Add 0xb8//页地址
#define LCDCol_Add 0x40//列地址
#define Start_Line 0xC0//行地址
#define clear_DDRAM 0x01
#define LCD_DAT P0 /*液晶数据总线*/
sbit LCDLcs=P2^4 ; /*片选1*/
sbit LCDRcs=P2^3 ; /*片选2*/
sbit LCD_RS=P2^2 ; /*数据/指令 选择*/
sbit LCD_RW=P2^1 ; /*读/写 选择*/
sbit LCD_E=P2^0 ; /*读/写 使能*/
void LCDdelay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++);
for(j=0;j<10;j++);
}
uchar read_state()
{
uchar sta;
LCD_RS=0; //状态
LCD_RW=1; //写
LCD_E=0;
LCDdelay(2);
LCD_E=1;
sta=LCD_DAT;
LCD_E=0;
return sta;
}
void check_state()
{
while(read_state() & 0x80);
}
uchar read_dat()
{
uchar dat;
check_state();
LCD_RS=1; //数据
LCD_RW=1; //读
LCD_E=0;
LCDdelay(2);
dat=LCD_DAT;
LCD_E=1;
LCDdelay(2);
LCD_E=0;
return dat;
}
void write_com(unsigned char cmdcode)
{
check_state();//检测LCD是否忙
LCD_RS=0;
LCD_RW=0;
P1=cmdcode;
LCDdelay(2);
LCD_E=1;
LCDdelay(2);
LCD_E=0;
}
void write_data(unsigned char LCDDispdata)
{
check_state();//检测LCD是否忙
LCD_RS=1;
LCD_RW=0;
P1=LCDDispdata;
LCDdelay(2);
LCD_E=1;
LCDdelay(2);
LCD_E=0;
}
void init_lcd()
{
// LCDdelay(100);
//LCDLcs=1;//刚开始关闭两屏
//LCDRcs=1;
// LCDdelay(100);
write_com(LCDLCDDisp_Off);
write_com(0x01); //写初始化命令
write_com(Page_Add+0);
// write_com(Start_Line+0);
write_com(LCDCol_Add+0);
write_com(LCDLCDDisp_On);
}
void Clr_Scr()
{
uchar i,j;
LCDLcs=0;
LCDRcs=0;
for(i=0;i<8;i++)
{
write_com(Page_Add+i);
for(j=0;j<64;j++)
{
write_com(LCDCol_Add+j);
write_data(0x00);
}
}
}
void dadian(uchar x,uchar y)
{ uchar page,col,yu,dat_,_dat;
if(x>=64)
{
LCDLcs=1;
LCDRcs=0;
col=x-64;
}
else
{
LCDLcs=0;
LCDRcs=1;
col=x;
}
page=y/8;
yu=y%8;
switch(yu)
{
case 0:
dat_=0x01;
break;
case 1:
dat_=0x02;
break;
case 2:
dat_=0x04;
break;
case 3:
dat_=0x08;
break;
case 4:
dat_=0x10;
break;
case 5:
dat_=0x20;
break;
case 6:
dat_=0x40;
break;
case 7:
dat_=0x80;
break;
}
write_com(Page_Add+page);
write_com(LCDCol_Add+col);
_dat=read_dat();
write_com(Page_Add+page);
write_com(LCDCol_Add+col);
write_data(_dat|dat_);
}
void main()
{ uchar lie=0;
uchar k=0xc0;
init_lcd();
Clr_Scr();
dadian(1,7); //不知道为什么如果是同一page同一列里面的两个点会覆盖 我用了读操作
dadian(1,1); //这一排和上面那一排的点会覆盖
dadian(50,7);
dadian(60,1);
while(1);
}
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define LCDLCDDisp_Off 0x3e
#define LCDLCDDisp_On 0x3f
#define Page_Add 0xb8//页地址
#define LCDCol_Add 0x40//列地址
#define Start_Line 0xC0//行地址
#define clear_DDRAM 0x01
#define LCD_DAT P0 /*液晶数据总线*/
sbit LCDLcs=P2^4 ; /*片选1*/
sbit LCDRcs=P2^3 ; /*片选2*/
sbit LCD_RS=P2^2 ; /*数据/指令 选择*/
sbit LCD_RW=P2^1 ; /*读/写 选择*/
sbit LCD_E=P2^0 ; /*读/写 使能*/
void LCDdelay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++);
for(j=0;j<10;j++);
}
uchar read_state()
{
uchar sta;
LCD_RS=0; //状态
LCD_RW=1; //写
LCD_E=0;
LCDdelay(2);
LCD_E=1;
sta=LCD_DAT;
LCD_E=0;
return sta;
}
void check_state()
{
while(read_state() & 0x80);
}
uchar read_dat()
{
uchar dat;
check_state();
LCD_RS=1; //数据
LCD_RW=1; //读
LCD_E=0;
LCDdelay(2);
dat=LCD_DAT;
LCD_E=1;
LCDdelay(2);
LCD_E=0;
return dat;
}
void write_com(unsigned char cmdcode)
{
check_state();//检测LCD是否忙
LCD_RS=0;
LCD_RW=0;
P1=cmdcode;
LCDdelay(2);
LCD_E=1;
LCDdelay(2);
LCD_E=0;
}
void write_data(unsigned char LCDDispdata)
{
check_state();//检测LCD是否忙
LCD_RS=1;
LCD_RW=0;
P1=LCDDispdata;
LCDdelay(2);
LCD_E=1;
LCDdelay(2);
LCD_E=0;
}
void init_lcd()
{
// LCDdelay(100);
//LCDLcs=1;//刚开始关闭两屏
//LCDRcs=1;
// LCDdelay(100);
write_com(LCDLCDDisp_Off);
write_com(0x01); //写初始化命令
write_com(Page_Add+0);
// write_com(Start_Line+0);
write_com(LCDCol_Add+0);
write_com(LCDLCDDisp_On);
}
void Clr_Scr()
{
uchar i,j;
LCDLcs=0;
LCDRcs=0;
for(i=0;i<8;i++)
{
write_com(Page_Add+i);
for(j=0;j<64;j++)
{
write_com(LCDCol_Add+j);
write_data(0x00);
}
}
}
void dadian(uchar x,uchar y)
{ uchar page,col,yu,dat_,_dat;
if(x>=64)
{
LCDLcs=1;
LCDRcs=0;
col=x-64;
}
else
{
LCDLcs=0;
LCDRcs=1;
col=x;
}
page=y/8;
yu=y%8;
switch(yu)
{
case 0:
dat_=0x01;
break;
case 1:
dat_=0x02;
break;
case 2:
dat_=0x04;
break;
case 3:
dat_=0x08;
break;
case 4:
dat_=0x10;
break;
case 5:
dat_=0x20;
break;
case 6:
dat_=0x40;
break;
case 7:
dat_=0x80;
break;
}
write_com(Page_Add+page);
write_com(LCDCol_Add+col);
_dat=read_dat();
write_com(Page_Add+page);
write_com(LCDCol_Add+col);
write_data(_dat|dat_);
}
void main()
{ uchar lie=0;
uchar k=0xc0;
init_lcd();
Clr_Scr();
dadian(1,7); //不知道为什么如果是同一page同一列里面的两个点会覆盖 我用了读操作
dadian(1,1); //这一排和上面那一排的点会覆盖
dadian(50,7);
dadian(60,1);
while(1);
}
你先预读一便数据试试,在_dat=read_dat();之前加read_dat();
我试过了 没有用T T
uchar 换uint 试试或unlong
肯定会覆盖,对同一个位置写7又写1,要保住刚才打的点,要将两个数进行位运算才行!
没有形参 仔细检查检查