#include "reg52.h" #include "zimo.c" unsigned char xdata LCD[128][8]; //设置坐标 #define set_x(x) LcdWCom(0x40+(x&127)%64) #define set_y(y) LcdWCom(0xb8+(y&7))
sbit LCD_DI =P1^0; sbit LCD_RW =P1^1; sbit LCD_E = P1^2; sbit LCD_Blight=P2^7; //背光控制 sbit LCD_CS2 = P3^6; // 液晶选择控制位 sbit LCD_CS1 = P3^5; /* sbit LCD_DI = P1^2; // 液晶选择控制位 sbit LCD_RW = P1^3; // 液晶读写控制位 sbit LCD_E = P1^4; // 液晶 CLK sbit LCD_RST = P2^4; sbit LCD_Blight=P2^6; // 背光控制 sbit LCD_CS2 = P2^3; // 液晶选择控制位 sbit LCD_CS1 = P3^7; */
#define DATA_PORT P0 #define SELECT_CS1 LCD_CS1 = 1; LCD_CS2 = 0; #define SELECT_CS2 LCD_CS1 = 0; LCD_CS2 = 1; #define NOP() _nop_();_nop_();_nop_();
//////////////////延时程序 void delay(unsigned int j) {unsigned int i; do{ for(i=0;i<10;i++); }while(j--); }
//////////////////////////////////////////////////////////////写命令 void LcdWCom(unsigned char dd) { delay(1); LCD_E=0; LCD_RW = 0; LCD_DI =0; LCD_CS1 = 1; LCD_CS2 = 1; DATA_PORT = dd; LCD_E =0; LCD_E =1; LCD_E =0; } ///////////////////////////////////////写数据 void LcdWDat(unsigned char x, y, dd) { LCD[x][y]=dd; LCD_DI = 1; if(x<64) { SELECT_CS1; } else{ SELECT_CS2; }DATA_PORT = dd; LCD_E = 0; LCD_E = 1; LCD_E = 0; } //////////////////////////////////////////////////////////清屏 void ClearDisp(void) { unsigned char x,y;
for(y=0; y<8; y++) { set_x(x); set_y(y); for(x=0; x<128; x++) { LcdWDat(x,y,0); } } }
///////////////////////////////////////////////////读数据 unsigned char LcdRDat(unsigned char x, y) { return LCD[x][y]; }
///////////////////////////////////////////////////写一个字节数据 void LcdDrawByte(unsigned char x, y, value) { unsigned char tmp,i; tmp = (63-(y&0x3f)); i = tmp%8; y = tmp/8; set_x(x); set_y(y); tmp = LcdRDat(x,y); tmp = ((0xff>>(8-i))&tmp)| (value<<i); LcdWDat(x,y,tmp); if(i && (++y)<8) { set_x(x); set_y(y); tmp = LcdRDat(x,y); tmp = ((0xff<<i)&tmp) | (value>>(8-i)); LcdWDat(x,y,tmp); } } ///////////////////////////////////////////////////写一个字节数据 //反显 /*void LcdDrawByte00(unsigned char x, y, value) { unsigned char tmp,i; value=~value; tmp = (63-(y&0x3f)); i = tmp%8; y = tmp/8;
set_x(x); set_y(y); tmp = LcdRDat(x,y); tmp = ((0xff>>(8-i))&tmp)| (value<<i); LcdWDat(x,y,tmp); if(i && (++y)<8) { set_x(x); set_y(y); tmp = LcdRDat(x,y); tmp = ((0xff<<i)&tmp) | (value>>(8-i)); LcdWDat(x,y,tmp); } } */ //////////////////////////////////////////////////////////写数据显示 void LcdDispWord(unsigned char x, y, unsigned char code *p,unsigned char line, length) { unsigned char i,j; for (i=0; i<line; i++) { for (j=0; j<length; j++) { LcdDrawByte(x+j,y-i*8, *p++); } } }
//////////////////////////////////////////////////////////写数据显示 //反显 /*void LcdDispWord00(unsigned char x, y, unsigned char code *p,unsigned char line, length) { unsigned char i,j; for (i=0; i<line; i++) { for (j=0; j<length; j++) { LcdDrawByte00(x+j,y-i*8, *p++); } } } */ //////////////////////////////////////画点 /*void LcdDrawDot(unsigned char x, y, flag) { unsigned char tmp,i;
i = 7-(y%8); y = (63-(y&0x3f))/8; set_x(x); set_y(y);
tmp = LcdRDat(x,y); if(flag) tmp |= (1<<i); else tmp &=~ (1<<i); LcdWDat(x,y,tmp); }
////////////////////画线 /*unsigned char LcdDrawLine(unsigned char x1, y1, x2, y2, flag) { unsigned char tmp; if(x1==x2)//X坐标相同 画直线 | { if(y1>y2) { tmp=y1; y1=y2; y2=tmp; } for(; y1<=y2; y1++) { LcdDrawDot(x1,y1,flag); } } else if(y1==y2) { if(x1>x2) { tmp=x1; x1=x2; x2=tmp; } for(; x1<=x2; x1++) { LcdDrawDot(x1,y1,flag); } } else return 1; } ///////////////////////////////画矩形 /*void LcdDrawRect(unsigned char x1,y1,x2,y2,flag) { LcdDrawLine(x1,y1,x2,y1,flag); LcdDrawLine(x1,y1,x1,y2,flag);
LcdDrawLine(x2,y1,x2,y2,flag); LcdDrawLine(x1,y2,x2,y2,flag);
} */
void DispWord1(void) //显示函数 { unsigned char i; for (i=0; i<8; i++) LcdDispWord(8+8*i,63,Zimo1,2,8); for (i=0; i<3; i++) LcdDispWord(64+16*i,63,Zimo2,2,16); for (i=0; i<7; i++) LcdDispWord(8+16*i,31,Zimo0,2,16); for (i=0; i<18; i++) LcdDispWord(0+7*i,15,Zimo3,2,8); // for (i=0; i<15; i++) // LcdDispWord(0+8*i,15,Zimo5,2,8); }
void InitLcd(void) //液晶初使化函数 { unsigned int j; // LCD_RST = 0; // 复位驱动芯片 for(j=0; j<500; j++) ; // LCD_RST = 1; LcdWCom(0x3f); // 打开显示 delay(1000); LcdWCom(0x3f); // 打开显示 ClearDisp(); }
main() { ClearDisp(); InitLcd(); LCD_Blight=0; delay(10000); DispWord1(); // DispWord2();
while(1) {} } |