|
一个12864的显示程序
自己写的一个12864的LCD程序,希望各位帮我看下代码有没有问题。
采用的是模拟IO直连的方式,没采用总线,E连与非门的方法。
#include
sbit DI = P2^0;
sbit RW = P2^1;
sbit CS1= P2^2;
sbit CS2= P2^3;
sbit E = P2^4;
sbit busy = P0^7;
sbit rst = P0^4;
#define disp_on 0x3f
#define disp_off 0x3e
#define firstrow 0xc0 //设置其始行
#define page 0xb8 //设置页地址
#define row 0x40 //设置列地址
unsigned char QING[32]={
/* 请 */
0x20,0x22,0xEC,0x00,0x20,0x22,0xAA,0xAA,
0xAA,0xBF,0xAA,0xAA,0xEB,0xA2,0x20,0x00,
0x00,0x00,0x7F,0x20,0x10,0x00,0xFF,0x0A,
0x0A,0x0A,0x4A,0x8A,0x7F,0x00,0x00,0x00
};
//延时
void delay(unsigned char time)
{
unsigned char i,j;
for(i=0;i<255;i++)
for(j=0;j
}
//忙检测
check_busy()
{
DI=0;
RW=1;
E =1;
while(busy==0&&rst==0);
E =0;
}
write_comand(unsigned char comand)
{
check_busy();
DI =0;
RW =0;
P0=comand;
E = 1;
delay(1);
E = 0;
}
write_data(unsigned char dispdata)
{
check_busy();
DI =1;
RW =0;
P0=dispdata;
E =1;
delay(1);
E =0;
}
//清屏
clear_src()
{
unsigned char i,j;
for(i=0;i<8;i++)
{
CS1=1,CS2=0;//清左屏
write_comand(page+i);
write_comand(row);//列地址指针自动加,不用管
for(j=0;j<64;j++)
{
write_data(0);
}
CS1=0,CS2=1;//清右屏
write_comand(page+i);
write_comand(row);
for(j=0;j<64;j++)
{
write_data(0);
}
}
}
//初始化
void lcd_init()
{
rst =0;
delay(500);
rst =1;
CS1=1,CS2=1;
delay(500);
write_comand(disp_off);
write_comand(disp_on);
//设置显示起始地址
write_comand(page);
write_comand(row);
write_comand(firstrow);
}
void disp_hz(unsigned char * hz)
{
unsigned char i;
for (i=0;i<16;i++) write_data(*(hz+i));
}
void main()
{
clear_src();
lcd_init();
while(1)
{
disp_hz(QING);
delay(5000);
}
}
程序显示一个汉字。多谢了,看有没有问题
[ 本帖最后由 frozenrain 于 2008-8-2 09:23 编辑 ]
|
|