小弟有个问题.这是我的程序,行地址和列地址我想修改,但是就是改不了,而且但我改了列地址y_address的初值时,显示还会出错.这是为什么?要怎样才能修改到行地址和列地址呢 #include<reg52.h> #define uint unsigned int #define uchar unsigned char #define true 1 uchar bw[61]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; uchar *p; uchar uci; uchar ucd; uchar ucc; //页地址加 uchar ucf; //列地址加 sbit E2=P3^7; //LCD右半屏使能端 sbit E1=P3^6; //LCD白箅屏使能端 sbit R_W=P3^5; //LCD的R/W端 sbit A0=P3^4; //LCD的A0端,1/0为:写数据/指令
uchar x_address; //LCD页地址 uchar y_address; //LCD列地址
void delay(uint x) { uchar ucy=125; while(x--) {for(ucy;ucy>0;ucy++); } }
void WRI(uci) //写指令 { E1=0; E2=0; A0=0; P2=uci; E1=1; E2=1; delay(2); E1=0; E2=0; } void WRD(ucd) //写数据 { //E1=0; E2=0; A0=1; P2=ucd; //E1=1; E2=1; delay(2); //E1=0; E2=0; } void Display_all(uchar LCD_data)//显示或熄灭全屏 { //WRI(0xe2); //复位 for(ucc=4;ucc>0;ucc--) { WRI(0xe2); //复位 WRI(x_address); //页地址 WRI(y_address); //列地址 WRI(0xe0); //“读-修改-写”模式设置,列地址加一 for(ucf=61;ucf>0;ucf--)//列地址加61次,满足一屏的列数 { WRD(LCD_data); //写数据 } WRI(0xee); //end x_address++; } } void black_white() { //x_address=0xb8; //页地址 初址0xb8 //y_address=0x00; //列地址 初址0x00 (设置出现问题) for(ucc=4;ucc>0;ucc--) { WRI(0xe2); //复位 WRI(x_address); //页地址 WRI(y_address); //列地址 WRI(0xe0); //“读-修改-写”模式设置,列地址加一 p=bw; for(ucf=61;ucf>0;ucf--)//列地址加61次,满足一屏的列数 { WRD(*p); delay(2);//延时2ms p++; //y_address++; } WRI(0xee); //end x_address++; } } main() { x_address=0xb8; //页地址 初址0xb8 y_address=0x00; //列地址 初址0x00 (设置出现问题) R_W=0; //写有效 WRI(0xaf); //显示模式设置 //WRI(0xcf); //START = 0 设置显示起始行(行地址设置出现问题) WRI(0xc0); WRI(0xa4); //静态驱动关 WRI(0xa9); //duty=1/32 WRI(0xa0); //反向显示(正向为0a0H)与原来成镜像 WRI(0xe2); //reset,从第一页开始显示,如果不是就从第三页开始显示 while(1) { //Display_all(0xff);//显示全屏 delay(5000); delay(5000); delay(5000); delay(5000); delay(5000); delay(5000); // //delay(200); black_white(); //显示黑和白 delay(5000); delay(5000); delay(5000); delay(5000); delay(5000); //Display_all(0x00);//熄灭全屏 }
}
|