?? lcd.c
字號:
/*******************************************************************************
- Chip : MG24500/55
- Author : RadioPulse Inc, 2007.
- Date : 2007-07-02
- Version : VER 1.0
*******************************************************************************/
#include "INCLUDE_TOP.h"
//--------------------------------------------------------------------
//
// LCD Usage
//
//--------------------------------------------------------------------
// STEP1 : GPIOs Direction is set to OUTPUT
// ZHAL_PORT0_INOUT_SET(0xA, 1);
// ZHAL_PORT1_INOUT_SET(0x4, 1);
// ZHAL_PORT1_INOUT_SET(0x6, 1);
// ZHAL_PORT1_INOUT_SET(0x7, 1);
// ZHAL_PORT3_INOUT_SET(0x4, 1);
// ZHAL_PORT3_INOUT_SET(0x5, 1);
//--------------------------------------------------------------------
// STEP2 : Initialize LCD
// ZHAL_LCD_INIT();
//--------------------------------------------------------------------
// STEP3 : Clear LCD and Display Data
// ZHAL_LCD_DIS_ALL(0x00);
// ZHAL_LCD_DIS_PUT_DATA(0, 0, radio_logo);
//--------------------------------------------------------------------
// Notice : If you want to display another data after initializing LCD, repeat STEP3.
//--------------------------------------------------------------------
// ================= KS0108 PORT Define ============================
#define LCM_DATA P0 // Data
#define LCM_RS P1_6 // Read select
#define LCM_RW P1_4 // Read/Write enable
#define LCM_E P1_7 // LCD enable
#define LCM_CS1 P3_4 // LCD Chip select
#define LCM_CS2 P3_5 // LCD Chip select
//*********** LCD Commend define **********************************
#define LCD_CMD_DISPON 0x3f // Display on "0011111x"
#define LCD_CMD_DISPOFF 0x3e // Display off "0011111x"
#define LCD_CMD_DISPLINE 0xc0 // Display Start Line "11xxxxxx"
#define LCD_CMD_PAGE 0xb8 // Set the x address "10111xxx"
#define LCD_CMD_COLUMN 0x40 // Set the Y address "01xxxxxx"
#define LCD_CMD_BUSY 0x80 // Read status
//************** *************************************************
#define LCD_MODL 0x00 //
#define LCD_MODM 0x40 //
#define LCD_MODR 0x80 //
#define LCD_LCMLIMIT 0x80 //
//**************** variable ***************************************
void ZHAL_LCD_DIS_STRING(UINT8 x,UINT8 y,UINT8 *str,UINT8 i,UINT8 ch8_16);
//*******************************************************************
// LCD Data
//*******************************************************************
UINT8 code STR1[] = "128x64 DOTS ";
UINT8 code STR2[]={0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87};
UINT8 LcdCol; // position X
UINT8 LcdRow; // position Y
UINT8 LcdData; // data
//*******************************************************************
// Delay Function
//*******************************************************************
void Delay_ForLCD(UINT16 t)
{
UINT16 i,j;
for(i=0;i<t;i++)
for(j=0;j<125;j++);
}
//*******************************************************************
// LCD STATUS CHECK FUNCTION
//*******************************************************************
//-- RETURN
// 0 : LCD is busy or LCD is not present.
// 1 : LCD is ready to run.
UINT8 ZHAL_LCD_BUSY()
{
UINT16 busy_cnt;
UINT8 busy_sta;
LCM_DATA = 0xFF;
LCM_RS = 0;
LCM_RW = 1;
LCM_E = 1;
//Port input mode
P0OEN = 0xFF;
busy_sta = 1;
for(busy_cnt=0 ; busy_cnt<5 ; busy_cnt++)
{
if( (LCM_DATA & 0x80) == 0)
{
busy_sta = 0;
break;
}
}
//Port output mode
P0OEN = 0x00;
_nop_();
LCM_E = 0;
return busy_sta;
}
//*******************************************************************
//WRITE Register Function
//*******************************************************************
void ZHAL_LCD_WR_CTRL_REG(UINT8 ctrl)
{
ZHAL_LCD_BUSY();
LCM_RW = 0;
LCM_RS = 0;
LCM_DATA = ctrl;
LCM_E = 1;
_nop_();
LCM_E = 0;
_nop_();
}
//*******************************************************************
//Read register
//*******************************************************************
UINT8 ZHAL_LCD_RD_CTRL_REG()
{
UINT8 ctrl;
ZHAL_LCD_BUSY();
LCM_RW = 1;
LCM_RS = 0;
LCM_E = 1;
_nop_();
ctrl = LCM_DATA;
LCM_E = 0;
_nop_();
return(ctrl);
}
//*******************************************************************
//Write Function
//*******************************************************************
void ZHAL_LCD_WR_DATA_REG(UINT8 dat)
{
ZHAL_LCD_BUSY();
LCM_RW = 0;
LCM_RS = 1;
LCM_DATA = dat;
LCM_E = 1;
_nop_();
LCM_E = 0;
_nop_();
}
//*******************************************************************
//Read Function
//*******************************************************************
UINT8 ZHAL_LCD_RD_DATA_REG()
{
UINT8 dat;
ZHAL_LCD_BUSY();
LCM_RW = 1;
LCM_RS = 1;
LCM_E = 1;
_nop_();
dat = LCM_DATA;
LCM_E = 0;
_nop_();
return(dat);
}
//*******************************************************************
/* LCM chip sel */
//*******************************************************************
void ZHAL_LCD_CS_LCM_L()
{
LCM_CS1 = 0; /*CLR CS1 */
LCM_CS2 = 1; /*SETB CS2 */
}
void ZHAL_LCD_CS_LCM_M()
{
LCM_CS1 = 1; /*SETB CS1 */
LCM_CS2 = 0; /*CLR CS2 */
}
//*******************************************************************
/*LCD address Set*/
//*******************************************************************
void ZHAL_LCD_ADDR_XY()
{
UINT8 x,y;
switch (LcdCol & 0xC0)
{
case 0x00 : ZHAL_LCD_CS_LCM_L(); break;
case 0x40 : ZHAL_LCD_CS_LCM_M(); break;
}
x = LcdCol&0x3F|LCD_CMD_COLUMN; // LcdCol.and.0x3f.or.setx
y = LcdRow&0x07|LCD_CMD_PAGE; // LcdRow.and.0x07.or.sety
ZHAL_LCD_WR_CTRL_REG(x);
ZHAL_LCD_WR_CTRL_REG(y);
}
//*******************************************************************
/* Write Data */
//*******************************************************************
void ZHAL_LCD_WR_DATA(UINT8 X)
{
ZHAL_LCD_ADDR_XY();
ZHAL_LCD_WR_DATA_REG(X);
}
//*******************************************************************
/* Write register L */
//*******************************************************************
void ZHAL_LCD_WR_CTRL_L(UINT8 X)
{
ZHAL_LCD_CS_LCM_L();
ZHAL_LCD_WR_CTRL_REG(X);
}
//*******************************************************************
/* Write register M */
//*******************************************************************
void ZHAL_LCD_WR_CTRL_M(UINT8 X)
{
ZHAL_LCD_CS_LCM_M();
ZHAL_LCD_WR_CTRL_REG(X);
}
//*******************************************************************
/* Clear LCD */
//*******************************************************************
void ZHAL_LCD_CLR_RAM()
{
for(LcdRow=0;LcdRow<8;LcdRow++)
{
for(LcdCol=0;LcdCol<LCD_LCMLIMIT;LcdCol++)
{
ZHAL_LCD_WR_DATA(0x00);
}
}
}
//*******************************************************************
// Display LCD ALL
//*******************************************************************
void ZHAL_LCD_DIS_ALL(UINT8 pattern)
{
for(LcdRow=0 ; LcdRow<8 ; LcdRow++)
{
for(LcdCol=0 ; LcdCol<LCD_LCMLIMIT ; LcdCol++)
{
ZHAL_LCD_WR_DATA(pattern);
}
}
}
//*******************************************************************
// Display LCD Row
//*******************************************************************
void ZHAL_LCD_DIS_ROW()
{
UINT8 i,dat;
ZHAL_LCD_CLR_RAM();
dat=0x55;
for(i=0;i<2;i++)
{
for(LcdRow=0;LcdRow<8;LcdRow++)
{
for(LcdCol=0;LcdCol<LCD_LCMLIMIT;LcdCol++)
ZHAL_LCD_WR_DATA(dat);
}
Delay_ForLCD(1000);
dat=~dat;
}
}
//*******************************************************************
// Display LCD Column
//*******************************************************************
void ZHAL_LCD_DIS_COL(void)
{
UINT8 i,dat;
ZHAL_LCD_CLR_RAM();
dat=0xff;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -