?? disp.c
字號:
/*
****************************************************
顯示
****************************************************
*/
#include <reg52.H>
#include "Typedef.H"
#include "UserDef.H"
#include "Disp.h"
#include "Font.H"
/* 端口定義 */
#define DISPDATAPORT P0 //數據端口
sbit Pin_CS1 = P2^1; //片選
sbit Pin_CS2 = P2^0; //片選
sbit Pin_RS = P2^2; //指令、數據選擇(0=指令;1=數據)
sbit Pin_RW = P2^3; //讀寫選擇(0=寫,1=讀)
sbit Pin_E = P2^4; //鎖存(下降沿有效)
sbit Pin_RST = P2^5; //鎖存(下降沿有效)
/* 全局變量 */
static INT8U idata DispPro[2][MAXDISPLEN]; //顯示屬性緩沖區
static INT8U CurRow = 0;
static INT8U CurCol = 0;
static INT8U CurFont = 0;
//顯示屬性定義
#define PRO_BLINK (1<<1) //閃爍
/***************************************
LCD忙等待
****************************************/
void Busy(void)
{
INT8U bf;
Pin_E = 0;
DISPDATAPORT = 0xFF; //使端口為輸入狀態
Pin_RW = 1; //讀
Pin_RS = 0; //指令
while (1)
{
Pin_E = 1;
bf = DISPDATAPORT;
Pin_E = 0;
if ((bf & 0x80) == 0)
break;
}
}
/***************************************
LCD數據寫
****************************************/
void LCD_Data(INT8U Data)
{
Busy();
Pin_E = 0;
Pin_RW = 0; //寫
Pin_RS = 1; //數據
Pin_E = 1;
DISPDATAPORT = Data;
Pin_E = 0;
}
/***************************************
LCD命令寫
****************************************/
void LCD_Cmd(INT8U cmd)
{
Busy();
Pin_E = 0;
Pin_RW = 0; //寫
Pin_RS = 0; //指令
Pin_E = 1;
DISPDATAPORT = cmd;
Pin_E = 0;
}
/***************************************
****************************************/
void LCD_Disp_Pattern(INT8U img,INT8U len)
{
INT8U col;
col = CurCol;
if (col<64)
Pin_CS1 = 1;
else
{
col -= 64;
Pin_CS2 = 1;
}
LCD_Cmd(0xB8|CurRow);
LCD_Cmd(0x40|col);
while (len != 0)
{
LCD_Data(img);
len --;
col ++;
CurCol ++;
if (col>=64)
{
Pin_CS1 = 0;
Pin_CS2 = 1;
LCD_Cmd(0xB8|CurRow);
LCD_Cmd(0x40|0);
col -= 64;
}
}
Pin_CS1 = 0;
Pin_CS2 = 0;
}
/***************************************
****************************************/
void LCD_Disp_Pic(INT8U * img,INT8U len)
{
INT8U col;
col =CurCol;
if (col<64)
Pin_CS1 = 1;
else
{
col -= 64;
Pin_CS2 = 1;
}
LCD_Cmd(0xB8|CurRow);
LCD_Cmd(0x40|col);
do
{
LCD_Data(*img);
len --;
col ++;
CurCol ++;
img ++;
if (col>=64)
{
Pin_CS1 = 0;
Pin_CS2 = 1;
LCD_Cmd(0xB8|CurRow);
LCD_Cmd(0x40|0);
col -= 64;
}
}while (len != 0);
Pin_CS1 = 0;
Pin_CS2 = 0;
}
/***************************************
顯示掃描刷新程序
****************************************/
void DispRef(void)
{
static INT8U BlinkCnt = 0; //閃爍顯示計數器
static BOOLEAN BlinkStatus = 0; //當前閃爍狀態
/* 計算顯示閃爍狀態 */
BlinkCnt ++;
BlinkCnt %= T_BLINK;
if (BlinkCnt == 0)
BlinkStatus = !BlinkStatus;
}
/***************************************
獲取整數的長度
****************************************/
static INT8U GetIntLen(INT32U val)
{
INT8U len;
len = 0;
while (val != 0)
{
val /= 10;
len ++;
}
if (len == 0)
len = 1;
return len;
}
/***************************************
顯示一個整數
入口參數:整數數值,起始顯示位置,長度
****************************************/
void DispInt(INT32U val,INT8U len)
{
}
/***************************************
顯示一個字符
入口參數:字符,顯示位置,是否閃爍
****************************************/
void DispChr(INT8U cv)
{
INT8U *pF;
INT8U len,n,row,col;
row = CurRow;
col = CurCol;
len = FontAttr[CurFont][0] * FontAttr[CurFont][1];
pF = (INT8U *)FontAdr[CurFont];
pF += cv*len;
n = 0;
while (1)
{
LCD_Disp_Pic(pF+n*FontAttr[CurFont][0],FontAttr[CurFont][0]);
n ++;
if (n>= FontAttr[CurFont][1])
break;
CurRow ++;
CurCol = col;
}
CurRow = row;
}
/***************************************
顯示一個字符
入口參數:字符,顯示位置,是否閃爍
****************************************/
void DispHZ(INT8U cv)
{
INT8U *pF;
INT8U n,row,col;
row = CurRow;
col = CurCol;
pF = (INT8U *)FontHZ14x14;
pF += cv*(14*2);
n = 0;
while (1)
{
LCD_Disp_Pic(pF+n*14,14);
n++;
if (n>= 2)
break;
CurRow ++;
CurCol = col;
}
CurRow = row;
}
/***************************************
顯示一個浮點數
注:無超顯示范圍判斷
使用全部的顯示區域
****************************************/
void DispFloat(float val,INT8U row,INT8U col,INT8U Len)
{
INT8U IntLen,n;
INT32U iv,ivf;
/* 符號位處理 */
if (val < 0)
{
// DispBuffer[row][col] = '-';
val = -val;
col ++;
Len --;
}
/* 整數位數計算 */
IntLen = GetIntLen((INT32U)val);
/* 整數部分 */
iv = (INT32U)val;
/* */
for (n=0;n<(Len-IntLen);n++)
{
val *= 10;
}
ivf = (INT32U)val;
ivf += 5;
ivf /= 10;
/* 顯示整數部分 */
DispInt(iv,IntLen);
/* 顯示小數點 */
// DispChr('.',row,col+IntLen ,FALSE);
/* 顯示小數部分 */
for (n=0;n<(Len-IntLen-1);n++)
{
// DispInt(ivf%10 , row , col + Len -n -1, 1);
ivf /= 10;
}
/* 計算實際有效位數,去掉小數部分尾數的所有0 */
n = col + Len - 1;
while (n >= IntLen)
{
// if (DispBuffer[row][n] != '0')
// {
// break;
// }
// DispBuffer[row][n] = ' ';
n --;
}
}
/***************************************
顯示清屏
****************************************/
void DispCls(void)
{
DispXYSet(0,0);
LCD_Disp_Pattern(0,128);
DispXYSet(1,0);
LCD_Disp_Pattern(0,128);
DispXYSet(2,0);
LCD_Disp_Pattern(0,128);
DispXYSet(3,0);
LCD_Disp_Pattern(0,128);
DispXYSet(4,0);
LCD_Disp_Pattern(0,128);
DispXYSet(5,0);
LCD_Disp_Pattern(0,128);
DispXYSet(6,0);
LCD_Disp_Pattern(0,128);
DispXYSet(7,0);
LCD_Disp_Pattern(0,128);
}
/***************************************
屏初始化
****************************************/
void DispInit(void)
{
INT16U i;
Pin_CS1 = 0;
Pin_CS2 = 0;
for (i=0;i<5000;i++)
Pin_RST = 0;
for (i=0;i<5000;i++)
Pin_RST=1; //使RST無效后延時一段時間(若不,則后續指令無效,原12864無需亦可???延時取255還不夠!!!)
Pin_E=0;
Pin_RS=1;
Pin_RW=1;
Pin_CS1 = 1;
LCD_Cmd(0x3F); //LCD_ON
LCD_Cmd(0xC0|0); //LCD_STARTLINE
LCD_Cmd(0xB8|0); //LCD_ROW
LCD_Cmd(0x40|0); //LCD_COL
Pin_CS1 = 0;
CurCol = 0;
CurRow = 0;
}
/***************************************
****************************************/
void DispXYSet(INT8U Row,INT8U Col)
{
CurRow = Row;
CurCol = Col;
}
/***************************************
****************************************/
void DispFontSet(INT8U Font)
{
CurFont = Font;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -