?? f14912864.txt
字號(hào):
#include <msp430x14x.h>
#define P2_0_RS 0x01 //數(shù)據(jù)指令控制位
#define P2_1_RW 0x02 //讀寫控制為
#define P2_2_EN 0x04 //液晶使能位
#define P2_3_CS1 0x08 //右片使能位
#define P2_3_CS2 0x40 //左片使能位
#define P2_3_RST 0x80 //液晶復(fù)位位
#define P5_0_DB0 0x01 //P5口為數(shù)據(jù)
#define P5_1_DB1 0x02
#define P5_2_DB2 0x04
#define P5_3_DB3 0x08
#define P5_4_DB4 0x10
#define P5_5_DB5 0x20
#define P5_6_DB6 0x40
#define P5_7_DB7 0x80
void delay(uint v) //調(diào)用延時(shí)
{
while(v>0)
{
v--;
}
}
void port_ini( void ) //程序初始化
{
P5DIR = 0xFF; //P5口定義為輸出
P5OUT = 0x00; //輸出為0
P2DIR = 0xFF; //p2口定義為輸出
P2OUT = P2_3_CS1 | P2_3_CS2 | P2_3_RST; //復(fù)位液晶全屏顯示,復(fù)位
P2OUT &=~P2_3_RST; //將復(fù)位端置低
_NOP();
_NOP();
P2OUT |= P2_2_EN; //液晶使能開
_NOP();
_NOP();
P2OUT &=~P2_2_EN; //關(guān)液晶使能
_NOP();
_NOP();
P2OUT |= P2_3_RST; //液晶復(fù)位
_NOP();
_NOP();
delay(400);
}
void write_command( uchar nByte ) //寫控制程序
{
P5DIR = 0xFF; //p5設(shè)置為輸出
P2OUT |= P2_3_CS1+P2_3_CS2; //選通左右屏
P2OUT &=~(P2_0_RS+P2_1_RW); //選定D0~D7發(fā)送的為指令數(shù)據(jù)
P5OUT = nByte; //p5輸出為 n位
P2OUT |= P2_2_EN; //液晶使能開
delay(10);
P2OUT &=~P2_2_EN; //液晶使能關(guān),E產(chǎn)生下降沿,使D0~D7數(shù)據(jù)發(fā)送到DRm
delay(400);
}
void write_char( uchar nByte, uchar CS1, uchar CS2 ) //寫數(shù)據(jù)程序
{
P5DIR = 0xFF; //p5設(shè)置為輸出
if(CS1) P2OUT |= P2_3_CS1; //當(dāng)cs1為高(選通)時(shí),p2_3_cs1口輸出高
else P2OUT &=~P2_3_CS1; //否則p2_3_cs1口輸出低
if(CS2) P2OUT |= P2_3_CS2; //當(dāng)cs2為高(選通)時(shí),p2_3_cs2口輸出高
else P2OUT &=~P2_3_CS2;//否則p2_3_cs2口輸出低
P2OUT |= P2_0_RS; //H,顯示數(shù)據(jù)。L,寫指令
P2OUT &=~P2_1_RW; //H,讀數(shù)據(jù)。L,寫數(shù)據(jù)
P5OUT = nByte;
P2OUT |= P2_2_EN; //下降沿鎖存數(shù)據(jù)。結(jié)合RW為L時(shí),數(shù)據(jù)寫到數(shù)據(jù)總線
delay(3);
P2OUT &=~P2_2_EN;
}
void clear_lcd( void ) //清屏
{
uchar i,j;
for(i=0;i<8;i++)
{
write_command(i|0xB8); //輸出行地址
write_command(0x40); //列出始地址
for(j=0;j<128;j++) //列地址遞增
{
if(j<=63) write_char(0,1,0); //判斷選通左右屏
else write_char(0,0,1);
_NOP();
}
}
}
void display_hz( uchar *chr, uchar nRow, uchar nCol )
{
uchar i,tmpCol;
write_command(0xB8|nRow);
tmpCol=nCol;
for(i=0;i<16;i++) //8*16(16點(diǎn)一字)掃描一字所占的十六行
{
if(tmpCol<=63) //掃描左/右屏的列位
{
write_command(0x40|tmpCol);
write_char(chr[i],1,0);
}
else
{
write_command(0x40|(tmpCol-64)); //右屏起始地址
write_char(chr[i],0,1); //選通右屏,chr[i]?
}
tmpCol++;
}
write_command(0xB8|nRow+1); //nrow+1???
tmpCol=nCol;
for(i=0;i<16;i++)
{
if(tmpCol<=63)
{
write_command(0x40|tmpCol);
write_char(chr[i+16],1,0);
}
else
{
write_command(0x40|(tmpCol-64));
write_char(chr[i+16],0,1); //i+16下一行初始地址
}
tmpCol++;
}
}
void display_8_16_icon( uchar *chr, uchar nRow, uchar nCol )
{
uchar i,tmpCol;
write_command(0xB8|nRow);
tmpCol=nCol;
for(i=0;i<8;i++)
{
if(tmpCol<=63)
{
write_command(0x40|tmpCol);
write_char(chr[i],1,0);
}
else
{
write_command(0x40|(tmpCol-64));
write_char(chr[i],0,1);
}
tmpCol++;
}
write_command(0xB8|nRow+1);
tmpCol=nCol;
for(i=0;i<8;i++)
{
if(tmpCol<=63)
{
write_command(0x40|tmpCol);
write_char(chr[i+8],1,0);
}
else
{
write_command(0x40|(tmpCol-64));
write_char(chr[i+8],0,1);
}
tmpCol++;
}
}
void display_char( uchar *chr, uchar nRow, uchar nCol )
{
uchar i,tmpCol;
write_command(0xB8|nRow);
tmpCol=nCol;
for(i=0;i<5;i++)
{
if(tmpCol<=63)
{
write_command(0x40|tmpCol);
write_char(chr[i],1,0);
}
else
{
write_command(0x40|(tmpCol-64));
write_char(chr[i],0,1);
}
tmpCol++;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -