网上下了好多测试程序,都显示不了,无字库的12864,分屏的,大神给帮忙看看,程序如下:#include <reg52.h>
#include"intrins.h"
#define uchar unsigned char
#define uint unsigned int
#define databus P0 //数据口
sbit RS=P2^6; //写指令/数据
sbit RW=P2^5; //读/写
sbit EN=P2^7; //使能
sbit CS1=P3^2;//片选1,控制左半屏,高电平有效
sbit CS2=P3^3;//片选1,控制右半屏,高电平有效
void delay(uchar ms) //延迟
{
uchar i;
uchar j;
for(i=0;i<100;i++)
for(j=0;j<ms;j++);
}
void busy() //忙检查
{
P0=0x00;
RS=0;
RW=1;
EN=1;
while(P0&0x80);
EN=0;
}
void write_cmd(uchar value)//写指令
{
busy();
RS=0;
RW=0;
EN=1;
databus=value;
EN=1;
delay(5);
EN=0;
}
void write_data(uchar value)//写数据
{
busy();
RS=1;
RW=0;
EN=1;
databus=value;
EN=1;
delay(5);
EN=0;
}
void set_page(uchar page)//设置页
{
page=0xb8||page;
write_cmd(page);
}
void set_line(uchar startline)//设置行
{
startline=0xc0|startline;
write_cmd(startline);
}
void set_column(uchar column)//设置列
{
column=column&0x3f;
column=0x40|column;
write_cmd(column);
}
void set_onoff(uchar onoff)//开关显示
{
onoff=0x3e|onoff;
write_cmd(onoff);
}
void slectscreen(uchar screen)//选择屏幕
{
switch(screen)
{
case 0:CS1=0;CS2=0;break;
case 1:CS1=0;CS2=1;break;
case 2:CS1=1;CS2=0;break;
default:break;
}
}
void clearscreen(uchar screen) //清屏
{
uchar i,j;
slectscreen(screen);
for(i=0;i<8;i++)
{
set_page(i);
set_column(0);
for(j=0;j<64;j++)
{
write_cmd(0x00);
}
}
}
void init() //初始化
{
busy();
slectscreen(0);
set_onoff(0);
slectscreen(0);
set_onoff(1);
clearscreen(0);
set_line(0);
}
void display(uchar ss,uchar page,uchar column,uchar *p) //显示函数
{
uchar i;
slectscreen(ss);
set_page(page);
set_column(column);
for(i=0;i<16;i++)
{
write_data(p[i]);
}
set_page(page+1);
set_column(column);
for(i=0;i<16;i++)
{
write_data(p[i+16]);
}
}
uchar code huan[]=
{0x00,0x08,0x18,0x28,0x08,0x08,0xE8,0x0F,0x18,0x20,0x1C,0x64,0x84,0x44,0x24,0x14,
0x00,0x20,0x60,0x30,0x18,0x06,0x03,0x0C,0x10,0x20,0x2C,0x43,0x43,0x4C,0x10,0x20,
};
uchar code ying[]=
{0x00,0x00,0xFC,0x04,0x04,0x04,0xFC,0x02,0x02,0x04,0xFC,0x00,0x04,0xCE,0x41,0x40,
0x00,0x40,0x43,0x44,0x42,0x40,0x5F,0x40,0x41,0x42,0x47,0x40,0x20,0x1F,0x20,0x40,
};
void main() //主函数
{
init();
clearscreen(0);
while(1)
{
set_line(1);
display(1,0,2*16,huan);
display(1,0,3*16,ying);
}
}
|