MSP430控制6963c驅(qū)動(dòng)液晶
/******************************************************************
讀液晶狀態(tài)字到STA
功能:用于往液晶寫數(shù)據(jù)或命令之前判斷忙閑
*******************************************************************/
voidread_sta(void)
{
P4DIR=0x00;//P4數(shù)據(jù)輸入
P3OUT=P3_2_DATAIO;//4245(x1)數(shù)據(jù)傳送方向選擇為:由液晶到430
P3OUT=P3_1_CD;//命令方式
P3OUT&=~P3_0_RD;//read
STA=P4IN;//讀回狀態(tài)
P3OUT=P3_0_RD;//CANcelread
P4DIR=0xff;//P4口置為數(shù)據(jù)輸出方式
P3OUT&=~P3_2_DATAIO;//4245(x1)數(shù)據(jù)傳送方向選擇為:由430到液晶
}
/*****************************************************************************
判狀態(tài)位S1,S0函數(shù)(讀寫指令和讀寫數(shù)據(jù)狀態(tài))
******************************************************************************/
voidST1(void)
{
do
{
read_sta();
}
while((STA&0x03)!=0x03);
}
/**********************************************************
判狀態(tài)位S2函數(shù)(數(shù)據(jù)自動(dòng)讀狀態(tài))
**********************************************************/
voidST2(void)
{
do
{
read_sta();
}
while((STA&0x04)!=0x04);
}
/***************************************************************
-判狀態(tài)位S3函數(shù)(數(shù)據(jù)自動(dòng)寫狀態(tài))-
****************************************************************/
voidST3(void)
{
do
{
read_sta();
}
while((STA&0x08)!=0x08);
}
/*****************************************************************************
寫入數(shù)據(jù)字節(jié)
******************************************************************************/
voidwrite_data(unsignedcharByte)
{
ST1();
P4OUT=Byte;
P3OUT&=~P3_1_CD;//數(shù)據(jù)方式
P2OUT&=~P2_7_WR;//write
P2OUT=P2_7_WR;
}
/*****************************************************************************
自動(dòng)寫入數(shù)據(jù)字節(jié)
******************************************************************************/
voidautowrite_data(unsignedcharByte)
{
P4OUT=Byte;
P3OUT&=~P3_1_CD;//數(shù)據(jù)方式
P2OUT&=~P2_7_WR;//write
P2OUT=P2_7_WR;
}
/*****************************************************************************
寫入命令字
******************************************************************************/
voidwrite_cmd(unsignedcharcmd)
{
ST1();
P4OUT=cmd;
P3OUT=P3_1_CD;//命令方式
P2OUT&=~P2_7_WR;//write
P2OUT=P2_7_WR;
}
/*****************************************************************************
寫只有一個(gè)參數(shù)的命令
******************************************************************************/
voidwrite_onepara(unsignedchardat1,unsignedcharcommand)
{
write_data(dat1);
write_cmd(command);
}
/*****************************************************************************
寫含有雙參數(shù)的命令
******************************************************************************/
voidwrite_doublepara(unsignedchardat1,unsignedchardat2,unsignedcharcommand)
{
write_data(dat1);
write_data(dat2);
write_cmd(command);
}
/*****************************************************************************
清顯示緩沖的函數(shù)
******************************************************************************/
voidCLEAR_RAM(void)
{
inti;
write_doublepara(0x00,0x00,0x24);/*設(shè)置顯示RAM首地址*/
write_cmd(0xb0);/*設(shè)置自動(dòng)寫方式*/
for(i=0;i<8200;i++)/*清8K存儲(chǔ)器*/
{
ST3();/*判狀態(tài)位S3*/
write_data(0x00);/*寫入數(shù)據(jù)*/
}
write_cmd(0xb2);/*設(shè)置自動(dòng)寫結(jié)束指令*/
}
/*****************************************************************************
對(duì)液晶屏的一些初始設(shè)置函數(shù)
******************************************************************************/
voidLCDIni(void)
{
write_doublepara(0x00,0x00,0x40);/*設(shè)文本顯示區(qū)域首地址*/
write_doublepara(0x28,0x00,0x41);/*設(shè)文本顯示區(qū)域?qū)挾?/
write_doublepara(0x03,0x00,0x22);/*設(shè)置CGRAM偏置地址*/
write_doublepara(0x00,0x08,0x42);/*設(shè)圖形顯示區(qū)域首地址*/
write_doublepara(0x1e,0x00,0x43);/*設(shè)圖形顯示區(qū)域?qū)挾?/
//write_cmd(0xa2);/*光標(biāo)形狀設(shè)置*/
//write_doublepara(0x08,0x08,0x21);/*設(shè)置光標(biāo)位置*/
write_cmd(0x80);/*顯示方式設(shè)置邏輯"或"合成,內(nèi)部字符發(fā)生器有效*/
write_cmd(0x98);/*顯示開關(guān)設(shè)置關(guān)文本和開圖形顯示*/
CLEAR_RAM();
}