MSP430f149上LCD顯示的程序【轉(zhuǎn)載】#include<msp430x14x.h>
void Init_lcd(void);
void LCD_DataWrite(char Data);
void Lcd_InsWrite(char Instruction);
/******************顯示時間*****************/
void main(void)
{
char i;
WDTCTL=WDTPW+WDTHOLD;
Init_lcd();
for(i=0;i<10;i++)
{
Lcd_InsWrite(0x84); //第一行
LCD_DataWrite(0xbb); // 歡
LCD_DataWrite(0xb6);
LCD_DataWrite(0xd3); //迎
LCD_DataWrite(0xad);
LCD_DataWrite(0xca); //使
LCD_DataWrite(0xb9);
LCD_DataWrite(0xd3); //用
LCD_DataWrite(0xc3);
Lcd_InsWrite(0x94); //第2行
LCD_DataWrite(0xce); // 無
LCD_DataWrite(0xde);
LCD_DataWrite(0xcf); //線
LCD_DataWrite(0xdf);
LCD_DataWrite(0xb3); //抄
LCD_DataWrite(0xad);
LCD_DataWrite(0xb1); //表
LCD_DataWrite(0xed);
LCD_DataWrite(0xa3); //!
LCD_DataWrite(0xa1);
Delay(5);
}
Lcd_InsWrite(0x01); //清除顯示
Delay(100);
Lcd_InsWrite(0x01); //清除顯示
Delay(100);
Lcd_InsWrite(0x80); //第一行
LCD_DataWrite(0xb3); //抄
LCD_DataWrite(0xad);
LCD_DataWrite(0xb1); //表
LCD_DataWrite(0xed);
LCD_DataWrite(0xc2); //嗎
LCD_DataWrite(0xf0);
LCD_DataWrite(0xa3); //?
LCD_DataWrite(0xbf);
Lcd_InsWrite(0x90); //第2行
LCD_DataWrite(0xd0); // 修
LCD_DataWrite(0xde);
LCD_DataWrite(0xb8); //改
LCD_DataWrite(0xa6);
LCD_DataWrite(0xca); //時
LCD_DataWrite(0xb1);
LCD_DataWrite(0xbc); //間
LCD_DataWrite(0xe4);
LCD_DataWrite(0xa3); //?
LCD_DataWrite(0xbf);
}
void Delay(int m)
{int i=0;
for(i=0;i<m;i++);
}
/************初始化LCD***********************/
void Init_lcd(void)
{
P4DIR =0XE0; //P4.7,P4.6,P4.5 輸出
Lcd_InsWrite(0x30);
Delay(400);
Lcd_InsWrite(0x0f); // 顯示狀態(tài)設(shè)定:整體顯示,游標(biāo)on,游標(biāo)位置反白
Delay(400);
Lcd_InsWrite(0x01); //清除顯示
Delay(400);
Lcd_InsWrite(0x06); //游標(biāo)向右移,AC自動加1
Delay(400);
Lcd_InsWrite(0x14); //游標(biāo)向右移
Delay(400);
}
/********************寫指令****************************/
void Lcd_InsWrite(char Instruction)
{
P5DIR=0XFF;
P4OUT&=0x3f; // RS=0 指令 // R/W=0 寫
P4OUT =BIT5; //E=1 使能
P5OUT=Instruction; //功能設(shè)定
Delay(3);
P4OUT&=~BIT5; //E=0:下降沿鎖存數(shù)據(jù)
P4OUT =BIT6+BIT7; //RS=1,E/W=1
}
/****LCD_WRITE.C 顯示文字*******************/
void LCD_DataWrite(char Data)
{
P5DIR=0XFF;
P4OUT =BIT7; //RS=1 寫數(shù)據(jù)
P4OUT&=~BIT6; //R/W=0 寫
P5OUT=Data; //寫數(shù)據(jù)
P4OUT =BIT5; //E=1 使能
Delay(3);
P4OUT&=~BIT5; //E=0鎖存
P4OUT =BIT6+BIT7; //RS=1,E/W=1
}