如题,不知道为啥,原因我找了很久了贴上程序
/********************** delay.h ************************/
/********************** delayms() ************************/
#include <reg52.h>
#include "lcd12864_parallel.h"
#include "delay.h"
sbit lcdrs = P3^5;
sbit lcdwr = P3^6;
sbit lcden = P3^4;
sbit lcdpsb = P3^7;
#define LCD_DATA P0
#define lcdrs_set lcdrs = 1
#define lcdrs_clr lcdrs = 0
#define lcdwr_set lcdwr = 1
#define lcdwr_clr lcdwr = 0
#define lcden_set lcden = 1
#define lcden_clr lcden = 0
#define lcdpsb_set lcdpsb = 1
#define lcdpsb_clr lcdpsb = 0
unsigned char lcd12864_test_busy(void)
{
unsigned char temp;
lcdrs_clr;
lcdpsb_set;
lcdwr_set;
lcden_set;
LCD_DATA = 0xff;
temp = LCD_DATA;
lcden_clr;
lcdwr_clr;
lcdrs_clr;
temp &= 0x80;
return temp;
}
unsigned char lcd12864_read_data(void)
{
unsigned char temp;
while(lcd12864_test_busy());
lcdrs_set;
lcdpsb_set;
lcdwr_set;
lcden_set;
LCD_DATA = 0xff;
temp = LCD_DATA;
lcden_clr;
lcdwr_clr;
lcdrs_clr;
return temp;
}
void lcd12864_write_cmd(unsigned char cmd)
{
while( lcd12864_test_busy() ) ;
lcdrs_clr;
lcdpsb_set;
lcdwr_clr;
lcden_clr;
LCD_DATA = cmd;
lcden_set;
lcden_clr;
}
void lcd12864_write_data(unsigned char date)
{
while( lcd12864_test_busy() ) ;
lcdrs_set;
lcdpsb_set;
lcdwr_clr;
lcden_clr;
LCD_DATA = date;
lcden_set;
lcden_clr;
}
void lcd12864_write_string(unsigned char *p)
{
while(*p != ' ')
{
lcd12864_write_data(*p);
p++;
}
}
void lcd12864_write_position(unsigned char x,unsigned char y)
{
if(x == 1)
{
lcd12864_write_cmd(0x80+y-1);
}
else if(x == 2)
{
lcd12864_write_cmd(0x90+y-1);
}
else if(x == 3)
{
lcd12864_write_cmd(0x88+y-1);
}
else if(x == 4)
{
lcd12864_write_cmd(0x98+y-1);
}
}
void lcd12864_init()
{
lcdpsb_set;
lcdwr_clr;
lcd12864_write_cmd(0x30);
lcd12864_write_cmd(0x02);
delayms(5); //这个一定得4.6ms以上
lcd12864_write_cmd(0x06);
lcd12864_write_cmd(0x0c);
lcd12864_write_cmd(0x01);
delayms(5); //这个一定得4.6ms以上
lcd12864_write_cmd(0x80);
}
void lcd12864_draw_point(unsigned char x,unsigned char y,unsigned char color)
{
unsigned char m,n; //m为该点的页数,n为改点在页中的比特数
unsigned char datah,datal; //datah为读出数据的高字节,datal为低字节
m = x >> 4;
n = x & 0x0f;
if(y >= 32)
{
y -= 32;
m += 8;
}
lcd12864_write_cmd(0x80+y);
lcd12864_write_cmd(0x80+m);
lcd12864_read_data();
datah = lcd12864_read_data();
datal = lcd12864_read_data();
if(n < 8)
{
switch(color)
{
/* case 0: datah &= (~( 0x01 >> n ));
break;
case 1: datah |= ( 0x01 >> n );
break;
case 2: datah ^= ( 0x01 >> n );
break;
default: break;
*/
case 0: datah &= (~( 0x01 >> (7-n) ));
break;
case 1: datah |= ( 0x01 >> (7-n) );
break;
case 2: datah ^= ( 0x01 >> (7-n) );
break;
default: break;
}
}
else
{
switch(color)
{
/* case 0: datal &= (~( 0x80 >> (15-n) ));
break;
case 1: datal |= ( 0x80 >> (15-n) );
break;
case 2: datal ^= ( 0x80 >> (15-n) );
break;
default: break;
*/
case 0: datal &= (~( 0x01 >> (15-n) ));
break;
case 1: datal |= ( 0x01 >>(15-n) );
break;
case 2: datal ^= ( 0x01 >> (15-n) );
break;
default: break;
}
}
lcd12864_write_cmd(0x80+y);
lcd12864_write_cmd(0x80+m);
lcd12864_write_data(datah);
lcd12864_write_data(datal);
}
void lcd12864_draw_horizontal_line(unsigned char xstar,unsigned char xend,unsigned char y)
{
unsigned char temp,i;
if(xstar > xend)
{
temp = xstar;
xstar = xend;
xend = temp;
}
lcd12864_write_cmd(0x34);
lcd12864_write_cmd(0x36);
for(i=xstar; i<=xend; i++)
{
lcd12864_draw_point(i,y,1);
}
lcd12864_write_cmd(0x30);
}
void lcd12864_draw_vertical_line(unsigned char x,unsigned char ystar,unsigned char yend)
{
unsigned char temp,i;
if(ystar > yend)
{
temp = ystar;
ystar = yend;
yend = temp;
}
lcd12864_write_cmd(0x34);
lcd12864_write_cmd(0x36);
for(i=ystar; i<=yend; i++)
{
lcd12864_draw_point(x,i,1);
}
lcd12864_write_cmd(0x30);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
-----------------------------------------------------------------------
嗯,你说的对。我上电之后清屏一下,就可以,不过两种清屏是不同的。
一周热门 更多>