?? lcddrivers.c
字號:
/**********************************************************
*YM12864R-3 液晶驅動(3線串行方式) LCD Module
*控制芯片:ST7920
*版本:V1.3
*日期:2007-6-6
*創建人:飛揚
**********************************************************/
#include <AT89x52.H>
/************* 用累加器操作速度比較快 *******************/
sbit B_0 = B^0;
sbit B_7 = B^7;
/****************** 液晶模塊引腳定義 *******************/
sbit LCD_CS = P1^0;//LCD模塊片選端,高電平有效
sbit LCD_SID = P1^1;//LCD串行數據輸入端
sbit LCD_CLK = P1^2;//LCD串行同步時鐘,上升沿讀取SID數據
/**************** 常用操作命令和參數定義 *****************/
#define DisplayClear 0x01 //清屏指令(00000001)
#define ReturnHome 0x02 //光標回到"00H"(0000001X)
#define EntryMode 0x06 //進入點設定,光標右移,AC加1(00000110)
#define DisplayOn 0x0c //整體顯示開,光標關,反白關
#define DisplayOff 0x08 //整體顯示關
#define CursorOn 0x0e //光標顯示開
#define Reverse 0x0d //反白顯示開
#define Basic 0x30 //基本指令
/************************************************/
#define Extend 0x34 //擴充指令
#define SleepOn 0x08 //進入睡眠模式
#define SleepOff 0x0c //脫離睡眠模式
#define PlotOn 0x36 //繪圖開
#define PlotOff 0x34 //繪圖關
#define uchar unsigned char //定義下方便使用
/**********************************************************
*函數名:SendData
*功能:發送數據
*說明:向LCD發送一個字節數據
*輸入:ucDat
*返回:無
**********************************************************/
void SendData(uchar ucDat)
{
uchar i;
B = ucDat;
for (i=8;i>0;i--)
{
LCD_CLK = 0;
LCD_SID = B_7;
LCD_CLK = 1;
B <<= 1;
}
}
/**********************************************************
*函數名:ReceiveData
*功能:接收數據
*說明:接收來自LCD的一個字節的數據
*輸入:無
*返回:B
**********************************************************/
uchar ReceiveData()
{
uchar i;
for (i=8;i>0;i--)
{
LCD_CLK = 0;
B <<= 1;
LCD_CLK = 1;
B_0 = LCD_SID;
}
return (B);
}
/**********************************************************
*函數名:ReadBusyFlag
*功能:讀忙碌標志和AC
*說明:
*輸入:
*返回:B
**********************************************************/
uchar ReadBusyFlag()
{
uchar ucDat1,ucDat2;
LCD_CS = 1;
SendData(0xfc); //發送讀忙碌標志指令
ucDat1 = ReceiveData();//
ucDat2 = ReceiveData();
LCD_CS = 0;
B = (ucDat2>>4)|(ucDat1&0xf0);
return (B);
}
/**********************************************************
*函數名:LCDWriteData
*功能:寫數據到LCD
*說明:
*輸入: Dat
*返回: 無
**********************************************************/
void LCDWriteData(uchar Dat)
{
uchar ucDat;
LCD_CS = 0;
do {
ucDat = ReadBusyFlag(); //忙碌判斷
} while (ucDat&0x80);
LCD_CS = 1;
SendData(0xfa); //發送寫數據指令
SendData(Dat&0xf0);//發送高4位
SendData(Dat<<4); //發送低4位
LCD_CS = 0;
}
/**********************************************************
*函數名:LCDWriteCommand
*功能:寫指令到LCD
*說明:
*輸入: Dat
*返回: 無
**********************************************************/
void LCDWriteCommand (uchar Dat)
{
uchar ucDat;
LCD_CS = 0;
do {
ucDat = ReadBusyFlag();//忙碌標志
} while (ucDat&0x80);
LCD_CS = 1;
SendData(0xf8); //發送寫指令到LCD
SendData(Dat&0xf0);//發送高4位
SendData(Dat<<4); //發送低4位
LCD_CS = 0;
}
/**********************************************************
*函數名: LCDInit
*功能:初始化
*說明:液晶初始化函數
*輸入:無
*返回:無
**********************************************************/
void LCDInit()
{
LCDWriteCommand(Basic); //基本指令集
LCDWriteCommand(DisplayOn); //顯示開,光標關,發白關
LCDWriteCommand(DisplayClear); //清屏
LCDWriteCommand(EntryMode); //進入點設定,光標右移,AC加1
}
/**********************************************************
*函數名:
*功能:
*說明:
*輸入:
*返回:
**********************************************************/
/**********************************************************
*函數名:
*功能:
*說明:
*輸入:
*返回:
**********************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -