/* **12864并行接口参考程序,控制器st7920 lcdfill(uchar i):fill the screen with i (纵向显示) lcdfill_upright(uchar disdata):fill the screen with disdata(横向显示disdata) clearGDRAM():fill the screen with 0.
*/
#include <reg51.h> #include <intrins.h> #include <string.h> #define uchar unsigned char //自定义关键字 #define LCD_DATA P0 //液晶数据口 P0 #define LOW 0 //低电平 #define HIGH 1 //高电平 #define OFF 0 //逻辑关 #define ON 1 //逻辑开 xdata uchar CS_ADDR _at_ 0xf000;//定义CS的地址 sbit BUSY_FLAG = P0^7; //液晶模块忙标志 sbit MPU_RS_CH = P1^0; //寄存器选择输入 RS sbit MPU_RW_CH = P1^1; //读写控制 RW //sbit MPU_ENABLE = P2^5; //使能控制 E sbit MPU_PS_CH = P1^3; //串/并传输控制 PSB sbit MPU_RESET = P1^4; //液晶复位控制 RST //----------------------------------------------- //液晶模块指令集定义 #define cClearDisplay 0x01 //清显示指令 #define cEntryModeSet 0x06 //设置输入模式 #define cDisplayOnCtrl 0x0c //设置开显控制 #define cFunctionSetB 0x30 //功能设定(基本指令) #define cFunctionSetE 0x34 //功能设定(扩充指令) //----------------------------------------------- void checkLcdBusy (void) { //LCD_DATA = 0xff; uchar temp; MPU_RS_CH = LOW; MPU_RW_CH = HIGH; //MPU_ENABLE = HIGH; temp = CS_ADDR; while (0x80&temp == 0x80); //MPU_ENABLE = LOW; } //=============================================== void delayMs (uchar ms) { uchar i; while (--ms) for (i = 0; i < 125; i++); } //=============================================== void delaySec (uchar sec) { uchar i; while (--sec) for (i = 0; i < 200; i++) delayMs (6); } //=============================================== void lcdWriteCommand (uchar Command) { checkLcdBusy(); MPU_RS_CH = LOW; MPU_RW_CH = LOW; //LCD_DATA = Command; //MPU_ENABLE = HIGH; CS_ADDR = Command; delayMs(2); //MPU_ENABLE = LOW; } //=============================================== void lcdClear (void) { lcdWriteCommand(cClearDisplay); } //=============================================== //=============================================== void lcdInit (void) //初始化LCD子程序 { MPU_PS_CH = HIGH; lcdWriteCommand(cFunctionSetE);//???????????????这句干嘛用的?????????????????不可同时改变G和RE?? lcdWriteCommand(cFunctionSetB); lcdClear(); lcdWriteCommand(cEntryModeSet); lcdWriteCommand(cDisplayOnCtrl); } //=============================================== void lcdWriteData (uchar Data) { checkLcdBusy(); MPU_RS_CH = HIGH; MPU_RW_CH = LOW; //LCD_DATA = Data; //MPU_ENABLE = HIGH; CS_ADDR = Data; delayMs(1); //MPU_ENABLE = LOW; }
//=============================================== /*=============================================== /*clearGDRAM it has the same funtion of lcdfill(0)*/ void clearGDRAM() { unsigned char x,y,ii; for(ii=0;ii<9;ii+=8) for(y=0;y<0x20;y++) for(x=0;x<8;x++) { lcdWriteCommand(0x36); lcdWriteCommand(y+0x80); //行地址 lcdWriteCommand(x+0x80+ii); //列地址 lcdWriteCommand(0x30); lcdWriteData(0); lcdWriteData(0); } } /*clearGDRAM ends*/
//整屏显示 //当ii=0时显示上面128×32 //当ii=8时显示下面128×32 void lcdfill(unsigned char disdata) { unsigned char x,y,ii; for(ii=0;ii<9;ii+=8) for(y=0;y<0x20;y++) for(x=0;x<8;x++) { // clearGDRAM(); lcdWriteCommand(0x36);//开绘图显示功能???????????????????????????????????? lcdWriteCommand(y+0x80); //行地址 lcdWriteCommand(x+0x80+ii); //列地址 // lcdWriteCommand(0x30);//?????????????同时改变RE和G??????????????而且把绘图显示功能关闭?????? lcdWriteData(disdata); lcdWriteData(disdata); lcdWriteCommand(0x30);//放这和前面都可以,RE改变时,其他(G)改变无效 } }
//当ii=0时显示上面128*8 //当ii=8时显示下面128×8 void lcdfill_upright(unsigned char disdata) { unsigned char x,y,ii; unsigned char i,f,k; for(ii=0;ii<9;ii+=8) for(y=0;y<4;y++) { f=disdata; for(i=0;i<8;i++) { if((f&1)==1) k=0xff; else k=0; for(x=0;x<8;x++) { lcdWriteCommand(0x36); lcdWriteCommand(y*8+i+0x80); lcdWriteCommand(x+0x80+ii); lcdWriteCommand(0x30);//放这和放下面都可以 lcdWriteData(k); lcdWriteData(k); //lcdWriteCommand(0x30);//放这和放上面都可以 } f>>=1; } } }
main() { unsigned char i; i=0x55; // RES=0; // _nop_(); // RES=1; // MPU_PS_CH=1; while(1) { // MPU_RW_CH=0; lcdInit(); //初始化LCD屏 lcdWriteCommand(0x01); delayMs(1000); lcdfill(0xff); delayMs(6000); lcdfill(i); //显示竖条 delayMs(6000); lcdfill_upright(i); //显示横条 delayMs(6000); lcdfill(0); lcdWriteCommand(0x01); delayMs(1000); // hzklib(); // lcdWriteCommand(4000); i=~i; } }
|