您的位置 首页 分销

MSP430单片机串行四线驱动1602液晶程序

includemsp430g2553hdefineucharunsignedchardefineuintunsignedintdefineRS_1P1OUT

#include “msp430g2553.h”

#define uchar unsigned char
#define uint unsigned int
#define RS_1 P1OUT|=BIT3;//输入数据
#define RS_0 P1OUT&=~BIT3;//输入指令
#define RW_1 P1OUT|=BIT4;//写入指令或许数据
#define RW_0 P1OUT&=~BIT4;//从lcd里边读取数据
#define EN_1 P1OUT|=BIT5;//读取信息
#define EN_0 P1OUT&=~BIT5;//下降沿时分履行指令
#define datt P2OUT;
uchar temp=0;
uchar table1[]={“hello”};
uchar table2[]={“hello”};

/*………………………………………….
* 延时程序
………………………………………….. */

void delay(uint i)
{
uint j;
while(–i!=0)
{
for(j=0;j<255;j++);
}
}

/*………………………………………….
* 忙信号查看
………………………………………….. */

uchar chkbusy()
{
uchar busy;
P2OUT=0xf0;
EN_0;//读取数据
RS_0;//输入指令
RW_1;//写入指令或许数据
EN_1;//读取信息
busy=P2OUT&0x80;
delay(1);
EN_0;//下降沿履行指令
return(busy);
}

/*………………………………………….
* 写指令
………………………………………….. */

void writecom(uchar x,uchar comm)
{
//if(x) while(chkbusy());
EN_0;
RS_0;
RW_0;
EN_1;
P2OUT=(comm&0xf0);
delay(5);
EN_0;
delay(5);
EN_1;
P2OUT=(comm&0x0f)<<4;
delay(5);
EN_0;
}

/*………………………………………….
* 写数据
………………………………………….. */

void writedata(uchar dat)
{

//while(chkbusy()); //查看忙信号
EN_0;
RS_1;
RW_0;
EN_1;
P2OUT=(dat&0xf0); //送高四位数据到P2口
delay(5);
EN_0;
delay(5);
EN_1;
P2OUT=(dat&0x0f)<<4; //送低四位数据到P2口
delay(5);
EN_0;
P2OUT=P2OUT|0x0f; //置低四位为1

}

/*………………………………………….
* lcd初始化程序
………………………………………….. */

voidadclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=17&is_app=0&jk=20c3646b7fe40062&k=lcd&k0=lcd&kdi0=0&luki=1&n=10&p=baidu&q=98059059_cpr&rb=0&rs=1&seller_id=1&sid=6200e47f6b64c320&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1831118&u=http%3A%2F%2Fwww%2E51hei%2Ecom%2Fmcu%2F2040%2Ehtml&urlid=0″ id=”1_nwl” mpid=”1″ target=”_blank”>lcdinit()
{
delay(30);
writecom(0,0×02);//数据指针清零
delay(5);
writecom(1,0×28);//
writecom(1,0x0c);//显现光标开及设置
writecom(1,0×06);//显现光标移动设置
writecom(1,0×01);//显现清屏
delay(10);
}

/*………………………………………….
* 在指定方位显现一个字符,x为行,Y为列
………………………………………….. */

void displayone(uchar x,uchar y,uchar *n)
{
uchar add;
if (x == 1) add=0x80+y;
//writecom(1,add);
else add=0xc0+y;
writecom(1,add);
writedata(*n);
}

/*………………………………………….
* 显现字符串
………………………………………….. */

void displayleng(uchar x,uchar y,uchar *s)
{
y=y&0x0f;
while(*s)
{
displayone(x,y,s);
y++;
s++;
}
}

/*………………………………………….
* 主函数
………………………………………….. */

void main()
{

WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P2SEL=0x00;
P2DIR = 0xff;
P1DIR = 0x38;

lcdinit();
//lcdcls();

P2OUT=0xff;

writecom(1,0×01);
//writedata(0x01);
while(1)
{
displayleng(1,0,table1);
delay(100);
displayleng(2,1,table2);
}
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/bandaoti/fenxiao/318193.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部