//mcumsp430f149//
//晶振内部dco//
//p43rs//
//p42r/w//
//p41e//
//p40rst//
//p30-p37db//
//===========================================================================//
#include
/*************************/
#defineUcharunsignedchar
#defineUintunsignedint
#defineUlongunsignedlong
Ucharbusy,hang,lie;
/********************************/
//定义字符串数组*/
/********************************/
charSTR2[]="http://www.qfmcu.com";;
charSTR3[]="http://www.mcubbs.net";;
/**************************定义函数原型********************************/
voidDelayus(Ulongilinshi);/*延时函数*/
voidBUSYLOOP();//*判忙函数*//
voidWrite_command(UcharCMD,Ucharbb);//*发控制字函数*//
voidWrite_data(UcharCMD);//*发数据函数*//
voidCHUSHIHUA();//*初始化函数*//
voidCLEAR();//*清屏*//
voidDisplay(Uchar*ptr,Ucharddram);//**显字符串函数**//
/*********************************************延时
**************************************/
//voidDelayus(Ulongt)
//{Ulongi,j;
//for(i=0;i//for(j=0;j//;
//}
voidDelayus(Ulongilinshi)
{Ulongii;
for(ii=0;ii}
//*********************判忙函数************************//
voidBUSYLOOP()
{//P1=0x0ff;
//do{
//P4OUT&=0xf7;//RS=0;
//P4OUT|=0x04;//RW=1;
//P4OUT|=0x02;//E=1;
//busy=P3IN;//BUSY=P1;
//P4OUT&=0xfd;//E=0;
//}
//while(busy>0x7f);
Delayus(10);
}
//*********************写控制字函数****************************//
voidWrite_command(UcharCMD,Ucharbb)
{
if(bb)
{BUSYLOOP();}
P4OUT&=0xf7;//RS=0;
P4OUT&=0xfb;//RW=0;
P4OUT|=0x02;//E=1;
P3OUT=CMD;//P1=CMD;
Delayus(10);
P4OUT&=0xfd;//E=0;
}
//*********************写数据函数****************************//
voidWrite_data(UcharCMD)
{BUSYLOOP();
//Delayus(1000);
P4OUT|=0x08;//RS=1;
P4OUT&=0xfb;//RW=0;
P4OUT|=0x02;//E=1;
P3OUT=CMD;//P1=CMD;
Delayus(10);
P4OUT&=0xfd;//E=0;
}
/***************************清屏*************************************/
voidCLEAR()
{P4OUT&=0xf7;//RS=0;
P4OUT&=0xfb;//RW=0;
P4OUT|=0x02;//E=1;
P3OUT=0x01;//P1=0x01;
Delayus(10);
P4OUT&=0xfd;//E=0;
}
//*************************液晶初始化********************************//
voidCHUSHIHUA()
{
Delayus(40000);
Write_command(0x30,0);
Delayus(1500);
Write_command(0x30,0);
Delayus(400);
Write_command(0x0C,1);
Delayus(1500);
Write_command(0x01,1);
Delayus(15000);
Write_command(0x06,1);
}
/*=======================================================
显示字符串
=======================================================*/
voidDisplay(Uchar*ptr,Ucharddram)
{
Ucharl,i1,x;
l=0;
if(ddram<0x88)
{hang=0;}//定位行地址:第一行
elseif(ddram<0x90)
{hang=2;}//定位行地址:第三行
elseif(ddram<0x98)
{hang=1;}//定位行地址:第二行
else
{hang=3;}//定位行地址:第四行
lie=0x0f&ddram;//定位列地址
if(lie>0x07)
{lie=lie-0x08;}
x=lie*2;
Write_command(ddram,0);//定位显示起始地址
while((ptr[l])!="\0")
{l++;}
for(i1=0;i1{Write_data(ptr[i1]);//输出单个字符
x++;
if(x==0x10)
{x=0;
hang++;
switch(hang)
{
case0:Write_command(0x80,0);
break;
case1:Write_command(0x90,0);
break;
case2:Write_command(0x88,0);
break;
case3:Write_command(0x98,0);
}
if(hang>3)
{
Write_command(0x80,0);
hang=0;
}
}
}
}
/**************************主函数开始***********************************/
main()
{WDTCTL=WDTPW+WDTHOLD;//停止看门狗
DCOCTL=0XE0;//初始化时钟
BCSCTL1=0X86;
BCSCTL2=0X00;
P3DIR=0xff;
P3OUT=0x00;
P4DIR=0x0f;
P4OUT=0x00;
////////////////////////////////
CLEAR();
CHUSHIHUA();//初始化函数//
Display(STR2,0x80);//上面一行显示一个预定字符串
Display(STR3,0x88);
Delayus(200);
Write_command(0x9C,0);//将光标移到0x9C
Write_command(0x0f,0);//光标处反白闪烁
//write_command(0x08,0);//进入睡眠状态
//delayus(200);
//write_command(0x0C,0);//唤醒
while(1)
{;}
}
/*************************主函数结束*************************************/