LCD12864驅動程序 帶字庫版本ST7920,內含簡單的畫點、線、圓、矩形和三角形函數以及任意尺寸圖像顯示。
單片機源程序如下:
- #include <reg51.h>
- #include "lcd12864.h"
- unsigned char code Photo2[];
- void main()
- {
- LCD12864_Init();
- LCD12864_WriteCmd(0x30);
- LCD12864_Display(0,3,"愛你 ");
-
- LCD12864_Drawing(56,0,Photo2); //在任意位置顯示任意比例圖片
-
- LCD12864_DrawLine_X(0,0,128,1); //水平線
-
- LCD12864_DrawLine_Y(0,0,64,1); //豎線
-
- LCD12864_DrawLine(0,0,50,50,1); //任意斜線
-
- LCD12864_DrawCircle(25,25,20,1); //圓
-
- LCD12864_DrawRetic(13,13,30,30,1); //矩形
-
-
- while(1)
- {
-
- }
- }
- unsigned char code Photo2[] ={
- /*-- 調入了一幅圖像:C:\Users\zhans\Pictures\Saved Pictures\我.bmp --*/
- /*-- 寬度x高度=71x64 --*/
- /*-- 寬度不是8的倍數,現調整為:寬度x高度=72x64 --*/
- 72,64,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x3F,0x00,
- 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x5F,0x8F,0xC0,0x00,0x00,0x01,0x00,0x00,0x00,
- 0x7F,0xDF,0xF0,0x00,0x00,0x01,0x00,0x00,0x00,0x7F,0xFF,0xFC,0x00,0x00,0x01,0x00,
- 0x00,0x03,0xFF,0xFF,0xFE,0x00,0x00,0x01,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0x00,0x00,
- 0x01,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0x00,0x00,0x01,0x00,0x00,0x3F,0xFF,0xFF,0xFF,
- 0x80,0x00,0x01,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xE0,0x00,0x01,0x00,0x00,0x7F,0xFF,
- 0xFF,0xFF,0xE0,0x00,0x01,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x01,0x00,0x00,
- 0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x01,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x03,
- 0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x03,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xF8,
- 0x00,0x03,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x13,0x00,0x01,0xFF,0xFF,0xFF,
- 0xFF,0xF8,0x00,0x03,0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x01,0x00,0x01,0xFF,
- 0xFF,0xFF,0xFF,0xF8,0x00,0x01,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x01,0x00,
- 0x01,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x01,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,
- 0x01,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x01,0x00,0x00,0x7F,0xFF,0xFF,0xFF,
- 0xE0,0x00,0x01,0x00,0x00,0x3F,0xF9,0xDF,0xFF,0xE0,0x00,0x01,0x00,0x00,0x3F,0xFC,
- 0x0F,0xFF,0xC0,0x00,0x01,0x00,0x00,0x1F,0x8C,0x03,0xEE,0x80,0x00,0x01,0x00,0x00,
- 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x01,0xF8,0x00,0xA0,0x00,0x00,0x01,
- 0x00,0x00,0x01,0x34,0x00,0x40,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼- //--------------------------------------------------------//
- //功能 :LCD12864驅動程序(帶字庫)
- //
- //--------------------[ZSX];QQ:1543588107-----------------//
- //--------------------------------------------------------//
- #include "lcd12864.h"
- //#include <math.h>
- /*******************************************************************************
- * 函 數 名 : LCD12864_Init
- * 函數功能 : 初始化LCD12864
- * 輸 入 : 無
- * 輸 出 : 無
- * 返 回 值 : 無
- *******************************************************************************/
- void LCD12864_Init()
- {
- LCD12864_RST = 1;
- LCD12864_RST = 0; //復位
- LCD12864_RST = 1;
-
- // LCD12864_WriteCmd(0x20); //4位數據 選擇基本指令操作 關繪圖
- LCD12864_WriteCmd(0x30); //8位數據 選擇基本指令操作 關繪圖
-
- LCD12864_WriteCmd(0x0c); //顯示開 關光標 不允許游標位置反白
- // LCD12864_WriteCmd(0x0e); //顯示開 開光標 不允許游標位置反白
- // LCD12864_WriteCmd(0x0d); //顯示開 關光標 允許游標位置反白
- // LCD12864_WriteCmd(0x0f); //顯示開 開光標 允許游標位置反白
-
- // LCD12864_WriteCmd(0x04); //讀取與寫入時游標向左移 地址自減1 顯示畫面整體不位移
- LCD12864_WriteCmd(0x06); //讀取與寫入時游標向右移 地址自加1 顯示畫面整體不位移
-
- // LCD12864_WriteCmd(0x10); //游標向左移動
- // LCD12864_WriteCmd(0x14); //游標向右移動
-
- LCD12864_GDRAMInit();
-
- LCD12864_WriteCmd(0x01); //清屏且地址歸位
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_Display
- * 函數功能 : 在基本指令模式下設置顯示坐標。注意:y是設置行,x是設置列
- * 輸 入 : x[in]列0~8 , y[in]行0~3 , Dat[in] 顯示數據
- * 輸 出 : 無
- * 返 回 值 : 無
- *******************************************************************************/
- void LCD12864_Display(unsigned char x, unsigned char y, unsigned char *Dat) //x[in]行0~3, y[in]列0~8, Dat[in] 顯示數據
- {
- unsigned char Addr;
- switch(y)
- {
- case 0: y = 0x80;break; //第一行的首地址是80H
- case 1: y = 0x90;break; //第二行的首地址是90H
- case 2: y = 0x88;break; //第三行的首地址是88H
- case 3: y = 0x98;break; //第四行的首地址是98H
- default :break;
- }
- Addr = x + y;
- LCD12864_WriteCmd(Addr);
-
- //檢測字符結束符('\0') 等同于 while(*Dat !='\0'); 注:只有字符串才有結束符'\0',單個字符
- while(*Dat) LCD12864_WriteData(*Dat++);
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_GDRAMInit
- * 函數功能 : 初始化GDRAM
- * 輸 入 : 無
- * 輸 出 : 無
- * 返 回 值 : 無
- * 說 明 :
- *******************************************************************************/
- void LCD12864_GDRAMInit() //初始化GDRAM
- {
- unsigned char x,y;
- for(y=0;y<64;y++)//64列 每行寫16個8字節取模數據
- for(x=0;x<16;x++)
- {
- LCD12864_WriteCmd(0x34); //開啟拓展指令集 關繪圖
- LCD12864_WriteCmd(0x80+y); //先寫列地址
- LCD12864_WriteCmd(0x80+x); //再寫行地址
- LCD12864_WriteCmd(0x30); //開啟基本指令集 關繪圖
- LCD12864_WriteData(0x00);
- LCD12864_WriteData(0x00);
- }
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_Drawing(畫圖)
- * 函數功能 : 在任意位置顯示任意比例圖片
- * 輸 入 : (x,y)[in] 顯示起始點 *img[in] 圖片顯示數據
- * 輸 出 : 無
- * 返 回 值 : 無
- * 說 明 :圖像取模方式為橫向取模,取模后的數據要在加上圖像的顯示比例
- 例如:uchar a[]={128,64,圖像數據};
- *******************************************************************************/
- void LCD12864_Drawing(unsigned char x,unsigned char y,unsigned char *img) //在任意位置顯示任意比例圖片
- {
- unsigned char xi,yi,tmp,xa,xb;
-
- xi=img[0]>>3; //除以8,每行字節數
- xa=x>>4; //起始行地址
- xb=x&0x0f; //起始行偏移地址
-
- for(yi=y;yi<(img[1]+y);yi++) //確定圖片的顯示區域
- {
- LCD12864_WriteCmd(0x34);//開啟拓展指令集 關繪圖
-
- if(yi<32) //顯示圖片上下半屏選擇(地址調整)
- {
- LCD12864_WriteCmd(0x80+yi); //先寫列地址
- LCD12864_WriteCmd(0x80+xa); //再寫行地址
- }
- else
- {
- LCD12864_WriteCmd(0x80+yi-32);//先寫列地址
- LCD12864_WriteCmd(0x88+xa); //再寫行地址
- }
-
- LCD12864_WriteCmd(0x30); //開啟基本指令集 關繪圖
-
- if(xb>=8) //起始行偏移地址
- {
- LCD12864_WriteData(0x00); //偏移超過8位時,則在第一字節位置補零
- LCD12864_WriteData(img[(yi-y)*xi+2]>>(xb-8)); //依據xb(起始行偏移地址)對圖像重新編碼
-
- for(tmp=0;tmp<xi-1;tmp++)
- LCD12864_WriteData((((unsigned int)(img[(yi-y)*xi+tmp+2])<<8)+img[(yi-y)*xi+tmp+3])>>(xb-8));//依據xb(起始行偏移地址)對圖像重新編碼
-
- LCD12864_WriteData((unsigned int)(img[(yi-y)*xi+xi+1])<<(16-xb));//依據xb(起始行偏移地址)對圖像重新編碼
- }
- else
- {
- LCD12864_WriteData(img[(yi-y)*xi+2]>>xb);//依據xb(起始行偏移地址)對圖像重新編碼
-
- for(tmp=0;tmp<xi-1;tmp++)
- LCD12864_WriteData((((unsigned int)(img[(yi-y)*xi+tmp+2])<<8)+(img[(yi-y)*xi+tmp+3]))>>xb);//依據xb(起始行偏移地址)對圖像重新編碼
-
- LCD12864_WriteData((unsigned int)(img[(yi-y)*xi+xi+1])<<(8-xb));//依據xb(起始行偏移地址)對圖像重新編碼
- }
- }
- LCD12864_WriteCmd(0x36); //開啟基本指令集 開繪圖
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_DrawPoint(畫,點)
- * 函數功能 : 在任意位置描點
- * 輸 入 : x[in] 0~127 水平坐標 y[in] 0~63 垂直坐標 color[in] 顏色 黑或白
- * 輸 出 : 無
- * 返 回 值 : 無
- *******************************************************************************/
- void LCD12864_DrawPoint(unsigned char x,unsigned char y,bit color) //在任意位置描點 x[in] 0~128 水平坐標 y[in] 0~64 垂直坐標 color[in] 顏色 黑或白
- {
- unsigned char seat,spot; //位置,點
- unsigned char Htmp,Ltmp;
-
- LCD12864_WriteCmd(0x36); //開啟基本指令集 開繪圖
-
- seat = x >> 4; //得出水平位置地址(高4位就是位置地址)
- spot = x & 0x0f; //得出點在水平位置地址的哪個地址(低4位就是點的位置)
-
- if(y >= 32){y-=32;seat+=8;} //大于32時,切換到下屏
-
- LCD12864_WriteCmd(0x80+y); //先寫垂直方向地址,指定在哪一行
- LCD12864_WriteCmd(0x80+seat); //再寫水平方向地址,指定在某一行具體地址
-
- LCD12864_ReadData(); //空讀一個數據,LCD必先假讀一次后才能正確讀出數據
-
- Htmp = LCD12864_ReadData();
- Ltmp = LCD12864_ReadData(); //讀完之后地址指針會改變,所以要重新寫一次地址
-
- LCD12864_WriteCmd(0x80+y); //先寫垂直方向地址,指定在哪一行
- LCD12864_WriteCmd(0x80+seat); //再寫水平方向地址,指定在某一行具體地址
- if(color) //描黑點
- {
- if(spot < 8) Htmp |= (1<<(7-spot)); //數據都是高位在前,即高位最靠近坐標(0,0)
- else Ltmp |= (1<<(15-spot));
- }
- else //描白點
- {
- if(spot < 8) Htmp &= ~(1<<(7-spot)); //數據都是高位在前,即高位最靠近坐標(0,0)
- else Ltmp &= ~(1<<(15-spot));
- }
-
- LCD12864_WriteData(Htmp); //寫入數據
- LCD12864_WriteData(Ltmp);
- LCD12864_WriteCmd(0x30); //開啟基本指令集
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_DrawLine_X(畫,線)
- * 函數功能 : 在任意位置描水平線
- * 輸 入 : (x0,y0) 起始坐標 x1[in] 垂直坐標 color[in] 顏色 黑或白
- * 輸 出 : 無
- * 返 回 值 : 無
- *******************************************************************************/
- void LCD12864_DrawLine_X(unsigned char x0,unsigned char y0,unsigned char x1,bit color) //在任意位置描水平線
- {
- unsigned char tmp;
-
- if(x0 > x1)
- {
- tmp = x1;
- x1 = x0;
- x0 = tmp;
- }
- do
- {
- LCD12864_DrawPoint(x0,y0,color);
- x0++;
- }
- while(x1 >= x0);
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_DrawLine_Y(畫,線)
- * 函數功能 : 在任意位置描豎線
- * 輸 入 : (x0,y0) 起始坐標 y1[in] 垂直坐標 color[in] 顏色 黑或白
- * 輸 出 : 無
- * 返 回 值 : 無
- *******************************************************************************/
- void LCD12864_DrawLine_Y(unsigned char x0,unsigned char y0,unsigned char y1,bit color) //在任意位置描豎線
- {
- unsigned char tmp;
-
- if(y0 > y1)
- {
- tmp = y0;
- y0 = y1;
- y1 = tmp;
- }
- while(y0 <= y1)
- {
- LCD12864_DrawPoint(x0,y0,color);
- y0++;
- }
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_DrawLine(畫,線)
- * 函數功能 : 在任意位置描任意線(插值法)
- * 輸 入 : (x0,y0) 起始坐標 (x1,y1) 終點坐標 color[in] 顏色 黑或白
- * 輸 出 : 無
- * 返 回 值 : 無
- * 說 明 :有bug.只能畫某些直線。
- *******************************************************************************/
- void LCD12864_DrawLine(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,bit color) //在任意位置描任意線
- {
- char dx_sym,dy_sym; //x,y軸的增值方向,-1,減;1,增
- char dx,dy; //x,y軸直線差值
- int dx_2,dy_2; //x,y軸直線差值的兩倍
- int di; //決策變量
-
- dx= x1-x0; //求兩點間的差值
- dy= y1-y0;
-
- if(dx>0) dx_sym= 1; //確定x軸增值方向
- else
- {
- if(dx<0) dx_sym= -1;
- else
- {
- LCD12864_DrawLine_Y(x0,y0,y1,color); //dx 為零 表示畫直線
- return;
- }
- }
-
- if(dy > 0) dy_sym = 1; //確定y軸增值方向
- else
- {
- if(dy < 0) dy_sym = -1;
- else
- {
- LCD12864_DrawLine_X(x0,y0,x1,color); //dy 為零 表示畫直線
- return;
- }
- }
-
- dx= dx_sym*dx; //dx,dy的取絕對值
- dy= dy_sym*dy;
-
- dx_2= dx*2;
- dy_2= dy*2;
-
- if(dx>=dy) //判斷 dx,dy的大小
- {
- di= dy_2-dx; //計算決策變量
- while(x0!=x1)
- {
- LCD12864_DrawPoint(x0,y0,color);
- x0+= dx_sym;
- if(di<0) di+= dy_2;
- else
- {
- di+= dy_2-dx_2;
- y0+= dy_sym;
- }
- }
- LCD12864_DrawPoint(x0,y0,color);
- }
- else
- {
- di= dx_2-dy; //計算決策變量
- while(y0!=y1)
- {
- LCD12864_DrawPoint(x0,y0,color);
- y0+=dy_sym;
- if(di<0) di+= dx_2;
- else
- {
- di+= dx_2-dy_2;
- x0= dx_sym;
- }
- }
- LCD12864_DrawPoint(x0,y0,color);
- }
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_DrawCircle(畫,圓)
- * 函數功能 : 在任意位置畫圓(使用bresenhan算法畫圓)
- * 輸 入 : (x0,y0) 圓心坐標 r[in] 半徑 color[in] 顏色 黑或白
- * 輸 出 : 無
- * 返 回 值 : 無
- *******************************************************************************/
- void LCD12864_DrawCircle(unsigned char x0,unsigned char y0,unsigned char r ,bit color) //在任意位置畫圓
- {
- char a=0,b,di; //變量一定要初始化,否則會出錯
-
- if(r > 31 || r==0) return;
-
- b = r;
- di = 3 - 2*r;
- while(a <= b)
- {
- LCD12864_DrawPoint(x0 - b,y0 - a,color); //3
- LCD12864_DrawPoint(x0 + b,y0 - a,color); //0
- LCD12864_DrawPoint(x0 - a,y0 + b,color); //1
- LCD12864_DrawPoint(x0 - b,y0 - a,color); //7
- LCD12864_DrawPoint(x0 - a,y0 - b,color); //2
- LCD12864_DrawPoint(x0 + b,y0 + a,color); //4
- LCD12864_DrawPoint(x0 + a,y0 - b,color); //5
- LCD12864_DrawPoint(x0 + a,y0 + b,color); //6
- LCD12864_DrawPoint(x0 - b,y0 + a,color); //8
-
- a++;
- if(di < 0) di += 4*a+6;
- else
- {
- di += 10+4*(a-b);
- b--;
- }
- LCD12864_DrawPoint(x0 + a,y0 + b,color);
- }
- // unsigned char xn,yn,xi,yi; //畫圓 //效果不好
- // unsigned int i;
- //
- // xn = cos(0)*r + x0;
- // yn = sin(0)*r + y0;
- //
- // for(i=0;i<630;i++)
- // {
- // xi = (cos(i*0.01)*r) + x0;
- // yi = (sin(i*0.01)*r) + y0;
- //
- // LCD12864_DrawLine(xn,yn,xi,yi,color);//在一系列零散的點上,兩點兩點之間連線從而得到一條曲線
- //
- // xn = xi;
- // yn = yi;
- // }
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_DrawRetic(畫,正方形)
- * 函數功能 : 畫正方形
- * 輸 入 : (x0,y0) 左上角坐標 (x1,y1) 右下角坐標 color[in] 顏色 黑或白
- * 輸 出 : 無
- * 返 回 值 : 無
- *******************************************************************************/
- void LCD12864_DrawRetic(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,bit color) //在任意位置畫正方形
- {
- LCD12864_DrawLine(x0,y0,x0,y1,color);//左豎
- LCD12864_DrawLine(x0,y0,x1,y0,color);//上橫
- LCD12864_DrawLine(x1,y0,x1,y1,color);//右豎
- LCD12864_DrawLine(x0,y1,x1,y1,color);//下橫
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_DrawTrigle(畫,三角形)
- * 函數功能 : 畫三角形
- * 輸 入 : (x0,y0) 頂角坐標 (x1,y1) 1邊角坐標 (x12,y2) 2邊角坐標 color[in] 顏色 黑或白
- * 輸 出 : 無
- * 返 回 值 : 無
- *******************************************************************************/
- void LCD12864_DrawTrigle(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,bit color) //在任意位置畫三角形
- {
- LCD12864_DrawLine(x0,y0,x1,y1,color);
- LCD12864_DrawLine(x1,y1,x2,y2,color);
- LCD12864_DrawLine(x2,y2,x0,y0,color);
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_ClearScreen
- * 函數功能 : 在畫圖模式下,LCD12864的01H命令不能清屏,所以要自己寫一個清
- * * 屏函數
- * 輸 入 : 無
- * 輸 出 : 無
- * 返 回 值 : 無
- *******************************************************************************/
- void LCD12864_ClearScreen()
- {
- unsigned char i,j;
- LCD12864_WriteCmd(0x34); //開啟拓展指令集
- for(i=0;i<32;i++) //因為LCD有縱坐標32格所以寫三十二次
- {
- LCD12864_WriteCmd(0x80+i); //先寫入縱坐標Y的值
- LCD12864_WriteCmd(0x80); //再寫入橫坐標X的值
- for(j=0;j<32;j++) //橫坐標有16位,每位寫入兩個字節的的數據,也
- { //就寫入32次以為當寫入兩個字節之后橫坐標會自
- LCD12864_WriteData(0xFF); //動加1,所以就不用再次寫入地址了。
- }
- }
- LCD12864_WriteCmd(0x36); //0x36擴展指令里面打開繪圖顯示
- LCD12864_WriteCmd(0x30); //恢復基本指令集
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_Delay1ms
- * 函數功能 : 延時1MS
- * 輸 入 : c
- * 輸 出 : 無
- * 返 回 值 : 無
- *******************************************************************************/
- void LCD12864_Delay1ms(unsigned int c)
- {
- unsigned char a,b;
- for(; c>0; c--)
- {
- for(b=199; b>0; b--)
- {
- for(a=1; a>0; a--);
- }
- }
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_mang
- * 函數功能 : 檢測LCD是否忙
- * 輸 入 : 無
- * 輸 出 : 1或0(1表示不忙,0表示忙)
- * 返 回 值 : 無
- *******************************************************************************/
- void LCD12864_mang()
- {
- unsigned char dat=0,i=0xff;
-
- LCD12864_RW = 1; //選擇讀取
- LCD12864_RS = 0; //選擇命令
- LCD12864_IO=0xff;
- do
- {
- LCD12864_EN = 1;
- dat=LCD12864_IO;
- LCD12864_EN = 0;
- }
- while((dat&0x80)&&(i--));
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_WriteCmd
- * 函數功能 : 寫命令
- * 輸 入 : cmd
- * 輸 出 : 無
- * 返 回 值 : 無
- *******************************************************************************/
- void LCD12864_WriteCmd(unsigned char cmd)
- {
- LCD12864_mang(); //檢忙
- LCD12864_RW = 0; //選擇寫入
- LCD12864_RS = 0; //選擇命令
- LCD12864_IO = cmd; //放置數據
- LCD12864_EN = 1; //寫時序
- LCD12864_EN = 0;
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_WriteData
- * 函數功能 : 寫數據
- * 輸 入 : dat
- * 輸 出 : 無
- * 返 回 值 : 無
- *******************************************************************************/
- void LCD12864_WriteData(unsigned char dat)
- {
- LCD12864_mang(); //檢忙
- LCD12864_RW = 0; //選擇寫入
- LCD12864_RS = 1; //選擇數據
- LCD12864_IO = dat; //放置數據
- LCD12864_EN = 1; //寫時序
- LCD12864_EN = 0;
- }
- /*******************************************************************************
- * 函 數 名 : LCD12864_ReadData
- * 函數功能 : 讀取數據
- * 輸 入 : 無
- * 輸 出 : 讀取到的8位數據
- * 返 回 值 : 無
- *******************************************************************************/
- unsigned char LCD12864_ReadData()
- {
- unsigned char dat;
- LCD12864_mang(); //檢忙
- LCD12864_RW = 1; //選擇讀取
- LCD12864_RS = 1; //選擇命令
- LCD12864_EN = 1;
- dat = LCD12864_IO;
- LCD12864_EN = 0;
- return dat;
- }
復制代碼
所有資料51hei提供下載:
LCD12864驅動函數(并口通信).rar
(86.29 KB, 下載次數: 337)
2018-8-19 17:00 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
lcd12864驅動程序 st7920(帶字庫版本).pdf
(306.93 KB, 下載次數: 215)
2018-8-18 19:47 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|