/********************************************
1602液晶显示
RW=0 程序中以默认 故并没有定义
*******************************************/
#include<msp430x14x.h>
#define uchar unsigned char
#define uint unsigned int
#define set_rs P5OUT|=BIT5
#define clr_rs P5OUT&=~BIT5
#define set_lcden P5OUT|=BIT7
#define clr_lcden P5OUT&=~BIT7
#define dataout P4DIR=0XFF
#define dataport P4OUT
const uchar table[]="lishuai";
const uchar table1[]="welcome!";
void int_clk()
{
unsigned char i;
BCSCTL1&=~XT2OFF; // 打开XT振荡器
BCSCTL2|=SELM1+SELS; // MCLK为8M,SMCLK为1M
do
{
IFG1&=~OFIFG; // 清除振荡器错误标志
for(i=0;i<100;i++)
_NOP(); // 延时等待
}
while((IFG1&OFIFG)!=0); //如果标志为1,则继续循环等待
IFG1&=~OFIFG;
}
void delay5ms(void)
{
unsigned int i=40000;
while (i != 0)
{
i--;
}
}
void write_com(uchar com) //1602写命令
{
clr_rs; //写命令
clr_lcden; //拉低
dataport=com;
delay5ms();
set_lcden; //拉高
delay5ms();
clr_lcden; //拉低
}
void write_date(uchar date) //1602写数据
{
set_rs; //写数据
clr_lcden; //拉低
dataport=date;
delay5ms();
set_lcden; //拉高
delay5ms();
clr_lcden; //拉低
}
void init()
{
uchar num;
clr_lcden;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<7;num++)
{
write_date(table[num]);
delay5ms();
}
write_com(0x80+0x40);
for(num=0;num<8;num++)
{
write_date(table1[num]);
delay5ms();
}
}
void main()
{
WDTCTL = WDTPW + WDTHOLD; //关闭开门狗
int_clk(); //初始化
P5DIR|=BIT5+BIT7;
dataout;
init();
while(1);
}
|