?? shiyan.c
字號:
#include <reg51.h>
#include <intrins.h>
#define GDM12864ADataPort P1 //LCD數據線
sbit DI=P2^2; // 數據\指令 選擇
sbit RW=P2^1; // 讀\寫 選擇
sbit EN=P2^0; // 讀\寫使能
sbit cs1=P2^4; // 片選1
sbit cs2=P2^3; // 片選2
sbit UP=P0^0;//定義UP
sbit DOWN=P0^1;//定義DOWN
sbit TEST=P3^0;//定義DOWN
unsigned char i,j,t;
static int nxx;
int t0,t1,t2,t3,tx,k,k0,k1,k2,k3;
//*--------函數列表-------
//狀態檢查
void CheckState()
{
unsigned char dat;
DI=0;
RW=1;
do{
GDM12864ADataPort=0x00;
EN=1;
dat=GDM12864ADataPort;
EN=0;
dat=0x80 & dat; //僅當第7位為0時才可操作(判別busy信號)
}while(!(dat==0x00));
}
/*-----------------------------------------------------------------------------------------------------*/
//向LCD發送命令
//command :命令
SendCommandToLCD(unsigned char command)
{
CheckState();
RW=0;
GDM12864ADataPort=command;
EN=1; EN=0;
}
/*----------------------------------------------------------------------------------------------------*/
//寫顯示數據
//dat:顯示數據
void WriteByte(unsigned char dat)
{
CheckState();
DI=1; RW=0;
GDM12864ADataPort=dat;
EN=1; EN=0;
}
/*----------------------------------------------------------------------------------------------------*/
//讀顯示數據
unsigned char ReadByte()
{
unsigned char dat;
CheckState();
DI=1; RW=1;
GDM12864ADataPort=0xff;
EN=1; dat=GDM12864ADataPort; EN=0;
return(dat);
}
/*----------------------------------------------------------------------------------------------------*/
//設定行地址(頁)--X 0-7
void SetLine(unsigned char line)
{
line=line & 0x07; // 0<=line<=7
line=line|0xb8; //1011 1xxx
SendCommandToLCD(line);
}
/*----------------------------------------------------------------------------------------------------*/
//設定列地址--Y 0-63
void SetColumn(unsigned char column)
{
column=column &0x3f; // 0=<column<=63
column=column | 0x40; //01xx xxxx
SendCommandToLCD(column);
}
/*----------------------------------------------------------------------------------------------------*/
//設定顯示開始行--XX
void SetStartLine(unsigned char startline) //0--63
{
startline=startline & 0x07;
startline=startline|0xc0; //1100 0000
SendCommandToLCD(startline);
}
/*----------------------------------------------------------------------------------------------------*/
//開關顯示
void SetOnOff(unsigned char onoff)
{
onoff=0x3e | onoff; //0011 111x
SendCommandToLCD(onoff);
}
/*---------------------------------------------------------------------------------------------------*/
//選擇屏幕
//screen: 0-全屏,1-左屏,2-右屏
void SelectScreen(unsigned char screen)
{ //cs1: 1--左; cs2: 1--右
switch(screen)
{ case 0: cs1=0;//全屏
_nop_(); _nop_(); _nop_();
cs2=0;
_nop_(); _nop_(); _nop_();
break;
case 1: cs1=0;//左屏
_nop_(); _nop_(); _nop_();
cs2=1;
_nop_(); _nop_(); _nop_();
break;
case 2: cs1=1;//右屏
_nop_(); _nop_(); _nop_();
cs2=0;
_nop_(); _nop_(); _nop_();
break;
}
}
/*---------------------------------------------------------------------------------------------------*/
//延時
GDM12864delay()
{
unsigned int i=500;
while(i--) {;}
}
/*---------------------------------------------------------------------------------------------------*/
//清屏
//screen: 0-全屏,1-左屏,2-右
void ClearScreen(unsigned char screen)
{ unsigned char i,j;
SelectScreen(screen);
for(i=0;i<8;i++){
SetLine(i);
for(j=0;j<128;j++){
WriteByte(0x00);
}
}
}
/*---------------------------------------------------------------------------------------------------*/
//初始化LCD
void InitLCD()
{ unsigned char i=250; //延時
while(i--);
SelectScreen(0);
SetOnOff(0); //關顯示
//ClearScreen(0);//清屏
SelectScreen(0);
SetOnOff(1); //開顯示
SelectScreen(0);
SetStartLine(0); //開始行:0
}
/*----------------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------*/
unsigned char code ASC[]={
/*.--0x2E */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x00,
/*'/'--0x2F */
0x00,0x00,0x00,0x80,0xC0,0x60,0x30,0x00,
0x0C,0x06,0x03,0x01,0x00,0x00,0x00,0x00,
/*0--0x30 */
0xF8,0xFC,0x04,0xC4,0x24,0xFC,0xF8,0x00,
0x07,0x0F,0x09,0x08,0x08,0x0F,0x07,0x00,
/*1--0x31 */
0x00,0x10,0x18,0xFC,0xFC,0x00,0x00,0x00,
0x00,0x08,0x08,0x0F,0x0F,0x08,0x08,0x00,
/*2--0x32 */
0x08,0x0C,0x84,0xC4,0x64,0x3C,0x18,0x00,
0x0E,0x0F,0x09,0x08,0x08,0x0C,0x0C,0x00,
/*3--0x33 */
0x08,0x0C,0x44,0x44,0x44,0xFC,0xB8,0x00,
0x04,0x0C,0x08,0x08,0x08,0x0F,0x07,0x00,
/*4--0x34 */
0xC0,0xE0,0xB0,0x98,0xFC,0xFC,0x80,0x00,
0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,
/*5--0x35 */
0x7C,0x7C,0x44,0x44,0xC4,0xC4,0x84,0x00,
0x04,0x0C,0x08,0x08,0x08,0x0F,0x07,0x00,
/*6--0x36 */
0xF0,0xF8,0x4C,0x44,0x44,0xC0,0x80,0x00,
0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00,
/*7--0x37 */
0x0C,0x0C,0x04,0x84,0xC4,0x7C,0x3C,0x00,
0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00,
/*8--0x38 */
0xB8,0xFC,0x44,0x44,0x44,0xFC,0xB8,0x00,
0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00,
/*9--0x39 */
0x38,0x7C,0x44,0x44,0x44,0xFC,0xF8,0x00,
0x00,0x08,0x08,0x08,0x0C,0x07,0x03,0x00
};
/*----------------------------------------------------------------------------------------------*/
#define CB6AB 0x0000 /*東 */
#define CC4CF CB6AB+32 /*南 */
//從左到右從上到下,縱向8點下高位分粗細體
unsigned char code Hztable[]={
//" "
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
//" "
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
//"唐"
0x00,0x00,0x00,0xFE,0xFC,0x84,0xA4,0xA4,
0xA5,0xFF,0xFE,0xA4,0xE4,0xF6,0xA4,0x80,
0x00,0x80,0x40,0x3F,0x1F,0xFC,0xFA,0x4A,
0x4A,0x4F,0x4F,0x4A,0xFB,0xFF,0x10,0x00,
//0x00,0x00,0xFC,0x44,0x54,0x54,0x54,0x55,
//0xFE,0x54,0x54,0x54,0xF6,0x44,0x40,0x00,
//0x40,0x30,0x0F,0x00,0xFD,0x45,0x45,0x45,
//0x47,0x45,0x45,0x45,0xFD,0x00,0x00,0x00,
//"山",
0x00,0x00,0xC0,0x80,0x00,0x00,0x00,0x00,
0xFE,0xFC,0x00,0x00,0x00,0x00,0xC0,0x80,
0x00,0x00,0xFF,0x7F,0x20,0x20,0x20,0x20,
0x3F,0x3F,0x20,0x20,0x20,0x20,0xFF,0x7F,
//"華",
0x00,0x40,0x20,0x30,0xFC,0xF7,0x02,0x80,
0x60,0xFF,0xFE,0x18,0x0E,0xC4,0x00,0x00,
0x00,0x08,0x08,0x08,0x0B,0x09,0x08,0xFE,
0xFE,0x09,0x0B,0x0B,0x0B,0x0B,0x0D,0x08,
//"光",
0x00,0x00,0x80,0x82,0xBC,0x98,0x80,0xFF,
0xFE,0x80,0xE0,0xB8,0x9E,0xC4,0x80,0x00,
0x00,0x80,0x80,0x40,0x60,0x38,0x1F,0x07,
0x00,0x7F,0xFF,0xC0,0xC0,0xC0,0xF0,0x40,
//" "
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
//" "
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -