字符型LCD12864 MSP430程序
/**********************************************************/
//MSP430 Advanced Developping Components - [LCD12864A_430.C]
////->>> http://www.just430.cn
////->>> tel 0)13500717874
/**********************************************************/
//MSP430高级实验开发组件 - LCD12864(字符型)液晶显示驱动
/*********************************************************/
#include
#define LCD_DI BIT7 //LCD_DI -> P2.7
#define LCD_DI_DIR P2DIR
#define LCD_DI_LO P2OUT &= ~LCD_DI
#define LCD_DI_HI P2OUT |= LCD_DI
#define LCD_RW BIT6 //LCD_RW -> P2.6
#define LCD_RW_DIR P2DIR
#define LCD_RW_LO P2OUT &= ~LCD_RW
#define LCD_RW_HI P2OUT |= LCD_RW
#define LCD_EN BIT5 //LCD_EN -> P2.5
#define LCD_EN_DIR P2DIR
#define LCD_EN_LO P2OUT &= ~LCD_EN
#define LCD_EN_HI P2OUT |= LCD_EN
#define LCD_PSB BIT0 //LCD_CS1 -> P6.0//PSB
#define LCD_PSB_DIR P6DIR
#define LCD_PSB_LO P6OUT &= ~LCD_PSB
#define LCD_PSB_HI P6OUT |= LCD_PSB
#define LCD_RST BIT2 //LCD_RST -> P6.2
#define LCD_RST_DIR P6DIR
#define LCD_RST_LO P6OUT &= ~LCD_RST
#define LCD_RST_HI P6OUT |= LCD_RST
#define LCD_DATA_IN P5IN
#define LCD_DATA_OUT P5OUT
#define LCD_DATA_DIR P5DIR
void LCD_Init(void);
void LCD_CheckBusy(void);
void LCD_Delayt(unsigned int dtime);
void LCD_WriteComm(unsigned char wdata);
void LCD_WriteByte(unsigned char wdata);
void LCD_SetXY(unsigned char X, unsigned char Y);
void LCD_WriteDEC(unsigned char X, unsigned char Y, unsigned char wdata);
void LCD_WriteString(unsigned char X, unsigned char Y, unsigned char *String);
unsigned char *aaa = "这是第一行吗?";
/*****************************************
void main(void) {
WDTCTL = WDTPW + WDTHOLD;
LCD_Init();
LCD_WriteComm(0x01);
while(1) {
LCD_WriteString(1,1,aaa);
LCD_Delayt(50000);LCD_Delayt(50000);LCD_Delayt(50000);LCD_Delayt(50000);
LCD_WriteString(1,1,"这是第一行的!");
LCD_Delayt(50000);LCD_Delayt(50000);LCD_Delayt(50000);LCD_Delayt(50000);
}
}
*****************************************/
void LCD_Delayt(unsigned int dtime) {
unsigned int itemp;
for(itemp=0;itemp}
void LCD_Init(void) {
LCD_PSB_DIR |= LCD_PSB; //PSB -> 并行模式
LCD_PSB_HI;
LCD_RST_DIR |= LCD_RST; //RST -> 复位输出
LCD_RST_LO; //复位状态
LCD_Delayt(1000);
LCD_DI_DIR |= LCD_DI;
LCD_DI_LO;
LCD_RW_DIR |= LCD_RW;
LCD_RW_LO;
LCD_EN_DIR |= LCD_EN;
LCD_EN_LO;
LCD_Delayt(1000);
LCD_RST_HI; //正常状态
LCD_WriteComm(0x30);
LCD_WriteComm(0x0c);
LCD_WriteComm(0x01);
LCD_WriteComm(0x02);
LCD_WriteComm(0x06);
}
void LCD_CheckBusy(void) {
unsigned char Flag;
LCD_DI_LO;
LCD_RW_HI;
LCD_DATA_DIR = 0x00;
do {
LCD_EN_HI;
Flag = LCD_DATA_IN;
LCD_EN_LO;
} while(Flag & 0x80);
LCD_DATA_DIR = 0xFF;
}
void LCD_WriteComm(unsigned char wdata) {
LCD_CheckBusy();
LCD_DI_LO;
LCD_RW_LO;
LCD_EN_HI;
LCD_DATA_OUT = wdata;
LCD_EN_LO;
}
void LCD_WriteByte(unsigned char wdata) {
LCD_CheckBusy();
LCD_DI_HI;
LCD_RW_LO;
LCD_EN_HI;
LCD_DATA_OUT = wdata;
LCD_EN_LO;
}
void LCD_SetXY(unsigned char X, unsigned char Y) {
switch(Y) {
case 1:
LCD_WriteComm(0x7F + X);
break;
case 2:
LCD_WriteComm(0x8F + X);
break;
case 3:
LCD_WriteComm(0x87 + X);
break;
case 4:
LCD_WriteComm(0x97 + X);
}
}
void LCD_WriteDEC(unsigned char X, unsigned char Y, unsigned char wdata) {
LCD_SetXY(X,Y);
LCD_WriteByte(wdata);
}
void LCD_WriteString(unsigned char X, unsigned char Y, unsigned char *String) {
unsigned char temp;
LCD_SetXY(X,Y);
temp = *String;
while(temp!=0) {
LCD_WriteByte(temp);
temp = *(++String);
}
}
用户1613410 2009-5-5 17:06