我想让PG12864自动写出它自带的128个字符,但是不能显示,麻烦各位大神指示一下
#include<reg51.h> #include<intrins.h> #define uchar unsigned char #define uint unsigned int
sbit wr=P2^0; sbit rd=P2^1; sbit CE=P2^2; sbit CD=P2^3; sbit RST=P2^4;
void delay(uchar t) { uchar i,j; for(j=0;j<t;j++) for(i=0;i<114;i++) ; } void write_data(uchar indata) { rd=1; CD=0; wr=0; CE=0; P0=indata; delay(10); wr=1; CD=1; CE=1; } void write_cmd(uchar cmd) { rd=1; CD=1; wr=0; CE=0; P0=cmd; delay(10); wr=1; CD=0; CE=1; } void check_status() //状态检查 { uchar sta; do { P0=0xff; CD=1; rd=0; sta=P0&0x03; rd=1; }while(sta!=0x03); } void write_cmd2(uchar dat,uchar cmd) { check_status(); write_data(dat); check_status(); write_cmd(cmd); } void write_cmd3(uchar data1,uchar data2, uchar cmd) { check_status(); write_data(data1); check_status(); write_data(data2); check_status(); write_cmd(cmd); } void clear_screen() { uint i; write_cmd3(0x00,0x00,0x24); check_status(); write_cmd(0xb0);//自动写 check_status(); for(i=0;i<8192;i++) { check_status(); write_data(0x00); } check_status(); write_cmd(0xb2);//结束自动写 } void L12864_int() { P2=0xff; RST=1; delay(10); RST=0; wr=1; rd=1; CE=1; CD=1; RST=1; check_status(); write_cmd3(0x01,0x00,0x21); 光标指针设置 check_status(); write_cmd3(0x00,0x00,0x40); //文本区首地址 check_status(); write_cmd3(16,0x00,0x41); check_status(); write_cmd(0x80);//显示方式设置 check_status(); write_cmd(0x94);//文本显示,不闪烁,不显示光标 check_status(); write_cmd(0xa1); //光标形状设置 } void display_char(uchar x,uchar y,uchar ch) { write_cmd3(((x*2)<<4+y),0x00,0x24); write_cmd2(ch-32,0xc0); } void main() { uchar i,j=0; L12864_int(); for(i=0;i<128;i++) { display_char(i/16,i%16,'0'+i); } clear_screen(); }
|