?? lcd12864_ks0108.c
字號:
/*LCD 12864 Control Instruction:KS0108
--------------------------------------------------------------------
|instruction RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 |
--------------------------------------------------------------------
|display on/off 0 0 0 0 1 1 1 1 1 0/1 | 開/關(guān)顯示:RS=R/W=0, 3E/3F
--------------------------------------------------------------------
|SET ADDRESS 0 0 0 1 Y ADDRESS(0~63) |
--------------------------------------------------------------------
|SET PAGE 0 0 1 0 1 1 1 (0~7) |
--------------------------------------------------------------------
|DISPLAY STATE LINE 0 0 1 1 (0~63) |
--------------------------------------------------------------------
|STATUS READ 0 1 Busy 0 on/off reset 0 0 0 0 |
|busy=0:ready,busy=1:in operation. on/off=0:display on,on/off=1:display off.
|reset=0:normal,reset=1:reset
-------------------------------------------------------------------
|write display data 1 0 (write data) |
--------------------------------------------------------------------
|read display data 1 1 (read data) |
--------------------------------------------------------------------
|12864液晶由左右兩屏組成,每屏由8x8點陣組成,由CS1、CS2選擇,共8頁(0~7),每頁8行(0~7)
---------------------------------------------------------------------------------------*/
#include <REG52.H>
#include <intrins.h>
#include <lcd12864.h>
#include "tunerval.h"
uchar data number=0;
sbit L_RS=P3^4;
sbit L_RW=P3^5;
sbit L_E=P3^3;
sbit L_CS2=P3^6;
sbit L_CS1=P3^7;
void busy(void)
{
L_RS=0;
L_RW=1;
P0=0xff;//read state;
L_E=1;
P0=P0&0x80;
L_E=0;
}
void LCD_C_D(bit flag,uchar data1) /*flag=1 CONTROL flag=0 data*/
{
uchar i;
busy();
L_RS = !flag; /*flag=0時,將數(shù)據(jù)D0_D7送入指令寄存器執(zhí)行 */
L_E = 0;
L_RW = 0; /* 寫數(shù)據(jù)*/
P0 = data1;
_nop_(); _nop_();_nop_();
L_E = 1;
_nop_(); _nop_();_nop_();
L_E = 0; /* L_E從高到底即下降沿鎖定數(shù)據(jù) */
L_RW = 1;/*讀出數(shù)據(jù)*/
L_RS = 1;/*將數(shù)據(jù)D0_D7送入指令寄存器執(zhí)行*/
for ( i = 0; i < 10 ;i++) ;
}
void dis_16x16(uchar x_add,uchar y_add,uchar *position)
/*dis_16x16(x,y,z):12864液晶能表示16x16大小的漢字共4行(0~3),8列(0~7)
其中x表示漢字顯示的行位置(例X=1表示第二行漢字行),
y表示列位置(例y=1表示第二列漢字列)
12864液晶共8頁(0~7),兩頁為一16x16漢字行*/
{
uchar i,j,w;
busy();
j = x_add*2+0xb8;/*設(shè)置需顯示的字的頁地址位置,B8=10111000:設(shè)置為第零頁地址,*/
w = (y_add < 4 ? y_add : y_add-4)*16+0x40;/* ?:條件運算符號(邏輯表達式?表達式1:表達式2),
要求有三個運算對象,首先計算邏輯表達式,其值為
真時將表達式1的值作為整個邏輯表達式的值,
為假時將表達式2的值作為整個邏輯表達式的值*/
+16為從二個漢字位置處顯示,字體為16x16大小*/
L_CS1 =!(y_add < 4);/*小于4字時選CS1半屏,一屏最多顯示4個16x16的漢字*/
L_CS2 =(y_add < 4);
LCD_C_D(1,j);/*設(shè)置需顯示的字的頁地址位置*/
LCD_C_D(1,w);/*設(shè)置需顯示的字的列地址位置*/
for (i = 0; i < 32;i++)
{
if (i == 16)/*數(shù)據(jù)為8位,每行128位,漢字字體為16x16,需32字節(jié),需兩頁才能顯示一個字,
必須向兩頁中對應(yīng)列送數(shù)據(jù),i=16就換頁顯示*/
{
LCD_C_D(1,j+1);/*設(shè)置需顯示的字的頁地址位置,即i=16時換頁顯示*/
LCD_C_D(1,w); /*設(shè)置需顯示的字的列地址位置,列位置不變*/
}
LCD_C_D(0,*position++);/*在指定位置顯示字,*position=P0=D0~D7 */
}
L_CS1 = L_CS2 = 0;
}
void dis_any_dot(uchar x_add,uchar y_add,uchar dot,uchar reverse)
{
uchar i,j,tem,tem1,tem2;
busy();
if(reverse==1){tem=~dot;}else tem=dot;//反白顯示
if(x_add==0){tem1=0x01|tem;}//第一頁要顯示上邊框
else if(x_add==7){tem1=0x80|tem;}//最后一頁要顯示下邊框
else tem1=tem;
if(y_add==0|y_add==127){tem2=0xff;}else tem2=tem1;//第一列要顯示左邊框,最后一列要顯示右邊框
i = x_add+0xb8;
j = (y_add < 64 ? y_add : y_add-64)+0x40;
L_CS1 =!(y_add < 64);
L_CS2 =(y_add < 64);
LCD_C_D(1,i);/*設(shè)置需顯示的字的頁地址位置*/
LCD_C_D(1,j);/*設(shè)置需顯示的字的列地址位置*/
LCD_C_D(0,tem2);/*在指定位置顯示字*/
L_CS1 = L_CS2 = 0;
}
void dis_6x8(uchar page,uchar row,uchar *character,uchar reverse)//顯示一行128列
{
uchar i;
for(i=0;i<6;i++){dis_any_dot(page,row+i,*character++,reverse);};
}
void dis_12x12(uchar page,uchar row,uchar *character,uchar reverse) //page:在第幾頁顯示;row:在第幾行顯示; reverse=1:反白顯示
{
uchar i;
for(i=0;i<24;i++)
{
if(i<12){dis_any_dot(page,row+i,*character++,reverse);}
else dis_any_dot(page+1,row+i-12,*character++,reverse);
};
}
void show_lcd_borad(void)
{
uchar i;
for(i=0;i<128;i++)
{
dis_any_dot(0,i,0x01,0);
dis_any_dot(7,i,0x80,0);
};
for(i=0;i<8;i++)
{
dis_any_dot(i,0,0xff,0);
dis_any_dot(i,127,0xff,0);
}
}
void CLRLCD(uchar number)
{
uchar i,j;
busy();
L_CS1 = L_CS2 = 1;
for (i = 0xb8; i < 0xc0;i++)/*選擇所有頁*/
{
LCD_C_D(1,i);
LCD_C_D(1,0X40);
for (j = 0; j < 0x40; j++)
LCD_C_D(0,number);
}
L_CS1 = L_CS2 = 0;
}
void lcd_init(void)
{ delay(100);
LCD_C_D(1,0X3E); /*L_RS=0,3E=111110:關(guān)顯示*/
LCD_C_D(1,0XC0); /*C0=11000000:從0行開始顯示*/
LCD_C_D(1,0X3F); /*開顯示*/
CLRLCD(0);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -