?? display.c
字號:
//##############################################################################
// 液晶控制操作單元
//##############################################################################
#include <msp430x16x.h>
#include "math.h"
#include "asc_cosd.h"
#include "display.h"
#define Uchar unsigned char //變量類型標識的宏定義
#define Uint unsigned int
unsigned int lcmcp,lcmdp;
//==============================================================================
//顯示緩存分配
#define BasePart1 0x00 //第一屏地址 0X0000 占用8K空間
#define BasePart2 0x40 //第二屏地址 0X4000 占用8K空間
#define BasePart3 0x80 //第三屏地址 0X8000 占用2K空間
#define BasePart4 0x00 //第四屏地址 0X0000 占用2K空間
//==============================================================================
//初始化參數配置數組
Uchar const ParaSysTable8[]= { 0x30,0x87,0x07,0x27,0x42,0xf0,0x28,0x00};
Uchar const ParaScrTableA[]= //{0x00,BasePart1,0xF0,0x00,BasePart2,0xF0,0x00,BasePart3,0x00,BasePart4};
{0x0000,0x0000,0x00F0,0x00b0,0x0004,0x00F0,0x0000,0x0000,0x0000,0x0000};
//{0x00,0x00,0xef,0xb0,0x04,0xef,0x00,0x00,0x00,0x00};
#define SystemSet 0x40 //1335控制器定義
#define Scroll 0x44
#define SleepIn 0x53
#define DispOn 0x59
#define DispOff 0x58
#define Ovlay 0x5b
#define HdotScr 0x5a
#define CsrForm 0x5d
#define CgramAdr 0x5c
#define CsrDirR 0x4c
#define CsrDirL 0x4d
#define CsrDirU 0x4e
#define CsrDirD 0x4f
#define CsrW 0x46
#define CsrR 0x47
#define mWrite 0x42
#define mRead 0x43
#define Busy 0x40 // 忙狀態標志位0b0100 0000
#define paraP9 0x28 // 相對于320 X 240
//##############################################################################
//**********************************************/
// 接口設置
// 8位數據 :(DB0--DB7)
// 輸出口 :
// 控制信號:(/RES,/A0,/CS,/WR,/RD)
// 輸出口:
//**********************************************/
void lcd_init_io(void)
{
// WDTCTL = WDTPW + WDTHOLD; // 關閉看門狗
KONGZHI_DIR = 0xff; //控制信號 /RES,C/D,CE,/WR,/RD
KONGZHI_OUT = 0xff;
SHUJU_DIR = 0xff; //數據端口 P6.0~P6.7 DB0~DB7
SHUJU_OUT = 0xff;
}
//***************************************************************************/
void Reset_lcd(void)
{
unsigned int i;
//------------------------------
//8080方式
RES_L; //reset=0
//------------------------------
for(i=100;i>0;i--)
{
_NOP();
}
RES_H; //reset=1
}
//***************************************************************************/
// clear textram
// 清除文本區
//***************************************************************************/
void clr_textram(void)
{
unsigned int i;
WriteCommand(0x4c); // Set direction of cursor movement
WriteCommand(0x46); // Set cursor address
WriteData(0);
WriteData(0);
WriteCommand(0x42); // Write to display memory
for(i=0;i<1200;i++)
{
WriteData(0x00); // 文本區寫數據 空格符
}
}
//***************************************************************************/
// clear graphics ram
// 清除圖形區
//***************************************************************************/
void clr_grphram(void)
{
unsigned int i;
WriteCommand(0x4c); // Set direction of cursor movement
WriteCommand(0x46); // Set cursor address
WriteData(0xb0);
WriteData(0x04);
WriteCommand(0x42); //Write to display memory
for(i=0;i<9600;i++)
{
WriteData(0x00); // 文本區寫數據 空格符
}
}
//***************************************************************************/
// LcmInition
// 液晶初始化
//***************************************************************************/
void LcmInition(void)
{
unsigned int i;
Reset_lcd();
//---------------------------------
WriteCommand(0x40); // Initialize device and display
for(i=0;i<8;i++)
{
WriteData(ParaSysTable8[i]); // 寫系統設置數據
}
WriteCommand(0x44); // Set display start address and display regions
for(i=0;i<10;i++)
{
WriteData(ParaScrTableA[i]); // 寫顯示控制數據
}
WriteCommand(0x5a); // Set horizontal scroll position
WriteData(0x00);
WriteCommand(0x5b); // Set display overlay format
WriteData(0x00);
clr_textram();
clr_grphram();
WriteCommand(0x59); //???? 58 Enable display flashing; 59 Disable display flashing
WriteData(0x14); // text graph on 04
//-----------------------------------
}
//################函數2.寫參數及顯示數據子程序#############################
//
// 寫參數及顯示數據子程序
//入口參數:dataW 將數據dataW 寫入SED1335
//*******************************************************
void WriteData( Uchar dataW ) {
CS1335_0; /*CS_0for430*/
A01335_0; /*A0_0for430*/
RD1335_1; /*RD_1for430*/
WR1335_0; /*WR_0for430*/
SHUJU_OUT=dataW;
WR1335_1;
A01335_1;
CS1335_1;
}
//################函數3.讀參數及顯示數據子程序#############################
//
// 讀參數及顯示數據子程序
// 讀出的參數 LcmRdataPort
//******************************************************
Uchar ReadDataLcm( void )
{
Uchar readdata1335;
P4DIR=0x00;
CS1335_0;
A01335_1;
WR1335_1;
RD1335_0;
readdata1335=SHUJU_IN;
RD1335_1;
A01335_1;
CS1335_1;
P4DIR=0xff;
return readdata1335;
}
//################函數4. 寫指令代碼子程序##################################
//
// 寫指令代碼子程序
//入口參數:CommandByte 將指令CommandByte寫入SED1335
//******************************************************
void WriteCommand( Uchar CommandByte ) {
CS1335_0; /*CS_0for430*/
A01335_1; /*A0_1for430*/
RD1335_1; /*RD_1for430*/
WR1335_0; /*WR_0for430*/
SHUJU_OUT=CommandByte;
WR1335_1;
CS1335_1;
}
//################函數5.延時子程序#########################################
//延時子程序1
//短暫延時參數tt
void Delay( Uint tt ) {
while( tt-- );
}
//################函數6.長延時程序#########################################
// 延時程序2
// 參數:count
// 延時: 1MS *COUNT
void DelayMs(Uint count)
{
Uint i,j;
for(i=0;i<count;i++)
for(j=0;j<120;j++)
;
}
//################函數8. 清顯示 32K RAM區(清屏)子程序######################
// 清顯示 32K RAM區(清屏)子程序
void LcmClear( void ) {
Uint i1=32768;
WriteCommand( CsrDirR ); // 光標移動方向定義:自動右移
WriteCommand( CsrW ); // 光標Locate,定位
WriteData( 0 ); // 寫入參數CSRL設置參數光標指針低8位
WriteData( 0 ); // 寫入參數CSRH設置參數光標指針高8位
WriteCommand( mWrite ); // 數據寫入指令,代碼0x42
while(i1--) {
WriteData( 0x0 ); // 寫入數據0
}
}
//#############################################################################################
// 滾動演示程序段 (包含向上,向下,向左,向右四個函數)
// 使用SED1335 等的屏幕滾動功能, 可以實現逐點滾動的顯示效果. 這個效果的實現, 在
// 水平方向是依賴于指令HDOT SET的支持. 下面的演示程序中看到HDOT SET指令的使用方法.
// 參數說明:V控制移動的速度。 tt控制移動的幅度
// 橫向移動的時候 tt控制移動的字節數目 縱向移動tt控制移動的點行數
//
//################函數15.滾動往左##########################
// 第一顯示區向左滾動
//V控制移動的速度。 tt控制移動的幅度 橫向移動的時候 tt控制移動的字節數目
void RollLaft( Uchar v,Uchar tt ) {
Uchar tempI,jj=tt;
Uint iTemp=0;
while(jj--) {
for(tempI=0;tempI<8;tempI++) {
WriteCommand( HdotScr ); // 寫入HDOT SET 指令
WriteData( tempI ); // 寫入參數
DelayMs(v); // 調延時子程序
}
iTemp ++;
}
// WriteCommand( Scroll ); // 設定顯示區域起始地址
// WriteData( (Uchar)(iTemp &amt; 0xff) ); // 寫入參數
// WriteData( (Uchar)(iTemp /256) ); // 寫入參數
}
//#################函數16.滾動往右######################
// 第一顯示區向右滾動
//V控制移動的速度。 tt控制移動的幅度 橫向移動的時候 tt控制移動的字節數目
void Rollright( Uchar v,Uchar tt ) {
Uchar tempI,jj=tt;
Uint iTemp=24;
while(jj--) {
tempI = 8;
WriteCommand( Scroll ); // 顯示區域(起點)設置
WriteData( (Uchar)(iTemp & 0xff) ); // 寫入參數
WriteData( (Uchar)(iTemp /256) ); // 寫入參數
while( tempI-- ) {
WriteCommand( HdotScr ); // 寫入HDOT SET 指令
WriteData( tempI ); // 寫入參數
DelayMs(v); // 調延時子程序
}
iTemp--;
}
}
//##################函數17.滾動往下##########################
// 第一顯示區向下滾動
//V控制移動的速度。 tt控制移動的幅度 縱向移動tt控制移動的點行數
void RollDown( Uchar v,Uchar tt ) {
Uchar jj = tt; // 演示32次
Uint iTemp=paraP9*50;
while(jj--) {
iTemp -= paraP9;
WriteCommand( Scroll ); // 設定顯示區域起始地址
WriteData( (Uchar)(iTemp & 0xff) ); // 寫入參數
WriteData( (Uchar)(iTemp /256) ); // 寫入參數
DelayMs(v); // 調延時子程序
}
WriteCommand( Scroll ); // 設定顯示區域起始地址
WriteData( 0 ); // 寫入參數
WriteData( 0 ); // 寫入參數
DelayMs(30);
}
//#####################函數18.向上滾動#########################
// 第一顯示區向上滾動
//V控制移動的速度。 tt控制移動的幅度 縱向移動tt控制移動的點行數
void RollUp( Uchar v,Uchar tt ) {
Uint iTemp=0;
Uchar jj = tt; // 演示30次
while(jj--) {
iTemp += paraP9;
WriteCommand( Scroll ); // 設定顯示區域起始地址
WriteData( (Uchar)(iTemp&0xff) ); // 寫入參數
WriteData( (Uchar)(iTemp /256) ); // 寫入參數
DelayMs(v); // 調延時子程序
}
WriteCommand( Scroll ); // 設定顯示區域起始地址
WriteData( 0 ); // 寫入參數
WriteData( 0 ); // 寫入參數
DelayMs(30);
}
//***************************************************************************/
void wr_cmd_2(unsigned int uCmd,unsigned int uPar) // 帶兩個參數的命令
{
lcmcp=uCmd;
WriteCommand(lcmcp);
lcmdp= uPar&0xff;
WriteData(lcmdp);
lcmdp=uPar>>8;
lcmdp&=0x00ff;
WriteData(lcmdp);
}
//***************************************************************************/
void wr_cmd_1(unsigned int uCmd,unsigned int uPar) // 帶一個參數的命令
{
lcmcp=uCmd;
WriteCommand(lcmcp);
lcmdp= uPar;
WriteData(lcmdp);
}
//***************************************************************************/
void wr_cmd_0(unsigned int uCmd) // 不帶帶參數的命令
{
lcmcp=uCmd;
WriteCommand(lcmcp);
}
//***************************************************************************/
//***************************************************************************/
void char_addr_point_set( unsigned int urow,unsigned int ucol)
{
unsigned int ipos;
ipos=urow*40+ucol+1200;
wr_cmd_0(0x004c);
wr_cmd_2(0x0046,ipos);
}
//***************************************************************************/
void showchar8(unsigned int row,unsigned int col,unsigned int chp,unsigned int attribute)
{// row:顯示行 col:顯示列 chp:顯示第幾個字. attribute:反色。1:顯示字黑,0顯示字白
unsigned int j,char_data;
const unsigned int *p;
p=&HZ8_DOT_LIB[0];
chp=chp*16;
p=p+chp; //指針指向顯示數字的地址
col/=8;
//----------------------------------------
// 顯示中文
//----------------------------------------
if(attribute)
{
for(j=0;j<16;j++)
{
char_addr_point_set(row,col); //設置Vram地址
WriteCommand(0x0042);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -