📄 12864lcd.h
字号:
#ifndef __12864lcd
#define __12864lcd
#endif
#include "math.h"
//*********************************************************************
//LCD matrix dispaly the BYTE and logo(lsd)
//
//
// MSP430F449
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|- ________
// | | | |
// | P2.0|-->| l |
// | . | . | |
// | P2.3| . | C |
// | P2.6| . | |
// | P2.7| . | D |
// | P3.0| . | |
// | . | . | |
// | P3.8|-->|________|
// | |
//
// 程序功能:该程序是128X64点阵的头文件
// 硬件连接:必须连接F449边上的p3.0-P3.7P4.0,P4.1,P2.6,P2.7口上的
// 短接器。另外,可以通过3296电位器R20来调节LCD灰度。
//
//typedef unsigned long DWORD;
typedef unsigned int WORD;
typedef unsigned char BYTE;
//****************************************************************************
#define P2_0_RS 0x01
#define P2_1_RW 0x02
#define P2_2_EN 0x04
#define P2_3_CS1 0x08
#define P2_6_CS2 0x40
#define P2_7_RST 0x80
#define P3_0_DB0 0x01
#define P3_1_DB1 0x02
#define P3_2_DB2 0x04
#define P3_3_DB3 0x08
#define P3_4_DB4 0x10
#define P3_5_DB5 0x20
#define P3_6_DB6 0x40
#define P3_7_DB7 0x80
#define Set_RS P2OUT |= P2_0_RS
#define Clr_RS P2OUT &=~P2_0_RS
#define Set_RW P2OUT |= P2_1_RW
#define Clr_RW P2OUT &=~P2_1_RW
#define Set_EN P2OUT |= P2_2_EN
#define Clr_EN P2OUT &=~P2_2_EN
#define Set_CS1 P2OUT |= P2_3_CS1
#define Clr_CS1 P2OUT &=~P2_3_CS1
#define Set_CS2 P2OUT |= P2_6_CS2
#define Clr_CS2 P2OUT &=~P2_6_CS2
#define Set_RST P2OUT |= P2_7_RST
#define Clr_RST P2OUT &=~P2_7_RST
#define LCD_CMD_DIR P2DIR
#define LCD_CMD_OUT P2OUT
#define LCD_DATA_DIR P3DIR
#define LCD_DATA_OUT P3OUT
#define LCD_DATA_IN P3IN
#define PixelModel_Draw 0x00 //画点
#define PixelModel_Clear 0x01 //清点
#define PixelModel_Not 0x02 //反色点
#define LineModel_Draw 0x00 //画线
#define LineModel_Clear 0x01 //清线
#define LineModel_Not 0x02 //反色线
#define BoxModel_Draw 0x00 //画边框
#define BoxModel_NoBox 0x03 //无边框
#define BoxModel_Clear 0x01 //画白色边框
#define BoxModel_Not 0x02 //边框反显
#define FillType_Fill 0x00 //填充黑色
#define FillType_Clear 0x01 //填充白色
#define FillType_Not 0x02 //填充反色
#define FillType_NoFill 0x03 //不填充
BYTE LCDStatus;
void write_command( BYTE nByte )
{
Clr_RS;
Set_RW; //RS=0,R/W=1,以便读液晶状态
LCD_DATA_DIR=0x00;
do
{
Set_EN; //E=1
LCDStatus=LCD_DATA_IN;
Clr_EN; //E=0
}
while((LCDStatus&0x80)!=0);
LCD_DATA_DIR = 0xFF;
LCD_CMD_OUT |= P2_3_CS1+P2_6_CS2;
LCD_CMD_OUT &=~(P2_0_RS+P2_1_RW);
LCD_DATA_OUT = nByte;
Set_EN;
Clr_EN;
}
void DisplayOnOff(BYTE i)// 显示开关控制命令,i=1开显示,i=0关显示
{
write_command( 0x3e+i );
}
//设置显示起始行,i=0~63//
void SetStartLine(BYTE i)
{
write_command( 0xc0+i );
}
//设置页(行)地址,i=0~7//
void Set_X(BYTE i)
{
write_command( 0xb8+i );
}
//设置Y(列)地址,i=0~127//
void Set_Y(BYTE i)
{
write_command( 0x40|i );
}
//写显示数据,i为送DDRAM的数据
void write_char( BYTE nByte )
{
Clr_RS;
Set_RW; //RS=0,R/W=1,以便读液晶状态
LCD_DATA_DIR=0x00; //P4口为输入口
do
{
Set_EN; //E=1
LCDStatus=LCD_DATA_IN;
Clr_EN; //E=0
}
while((LCDStatus&0x80)!=0);
LCD_DATA_DIR = 0xFF;
Set_RS;
Clr_RW;
LCD_DATA_OUT = nByte;
Set_EN;
Clr_EN;
}
BYTE read_char( void )
{
BYTE Rdata=0x00;
Clr_RS;
Set_RW; //RS=0,R/W=1,以便读液晶状态
LCD_DATA_DIR=0x00; //P4口为输入口
do
{
Set_EN; //E=1
LCDStatus=LCD_DATA_IN;
Clr_EN; //E=0
}
while((LCDStatus&0x80)!=0);
Set_RS; //RS=1
Set_RW; //R/W=1
Set_EN; //E=1
Clr_EN;
Set_EN;
_NOP();
Rdata=LCD_DATA_IN;
Clr_RS;
Set_RW; //RS=0,R/W=1,以便读液晶状态
LCD_DATA_DIR=0x00; //P4口为输入口
do
{
Set_EN; //E=1
LCDStatus=LCD_DATA_IN;
Clr_EN; //E=0
}
while((LCDStatus&0x80)!=0);
Set_RS; //RS=1
Set_RW; //R/W=1
Set_EN; //E=1
Clr_EN;
Set_EN;
_NOP();
Rdata=LCD_DATA_IN;
//E=0
return Rdata;
}
void clear_lcd( void )
{
BYTE i,j;
for(i=0;i<8;i++)
{
Set_X(i);
Set_Y(0);
for(j=0;j<128;j++)
{
if(j<=63)
{
Set_CS1;
Clr_CS2;
write_char(0x00);
}
else
{
Clr_CS1;
Set_CS2;
write_char(0x00);
}
}
}
}
void lcd_init( void )
{
LCD_DATA_DIR = 0xFF; //数据口设为输出
LCD_DATA_OUT = 0x00;
LCD_CMD_DIR = 0xFF;
P2OUT = P2_3_CS1 | P2_6_CS2 | P2_7_RST;
Clr_RST;
_NOP();
_NOP();
Set_EN;
_NOP();
_NOP();
Clr_EN;
_NOP();
_NOP();
Set_RST;
_NOP();
_NOP();
SetStartLine(0);
DisplayOnOff(1);
}
void display_hz( BYTE *chr, BYTE nRow, BYTE nCol ) //16×16汉字输出(下半烈排)
{
BYTE i,tmpCol;
Set_X(nRow); //页地址(x)设定
tmpCol=nCol;
for(i=0;i<16;i++)
{
if(tmpCol<=63)
{
Set_Y(tmpCol);
Set_CS1;
Clr_CS2;
write_char(chr[i]);
}
else
{
Set_Y(tmpCol-64);
Clr_CS1;
Set_CS2;
write_char(chr[i]);
}
tmpCol++;
}
Set_X(nRow+1);
tmpCol=nCol;
for(i=0;i<16;i++)
{
if(tmpCol<=63)
{
Set_Y(tmpCol);
Set_CS1;
Clr_CS2;
write_char(chr[i+16]);
}
else
{
Set_Y(tmpCol-64);
Clr_CS1;
Set_CS2;
write_char(chr[i+16]);
}
tmpCol++;
}
}
void display_16_16_icon( BYTE *chr, BYTE nRow, BYTE nCol )
{
BYTE i,tmpCol;
Set_X(nRow);
tmpCol=nCol;
for(i=0;i<16;i++)
{
if(tmpCol<=63)
{
Set_Y(tmpCol);
Set_CS1;
Clr_CS2;
write_char(chr[i]);
}
else
{
Set_Y(tmpCol-64);Clr_CS1;
Set_CS2;
write_char(chr[i]);
}
tmpCol++;
}
Set_X(nRow+1);
tmpCol=nCol;
for(i=0;i<16;i++)
{
if(tmpCol<=63)
{
Set_Y(tmpCol);
Set_CS1;
Clr_CS2;
write_char(chr[i+16]);
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -