新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > MSP430單片機(jī)串行四線驅(qū)動(dòng)1602液晶程序

MSP430單片機(jī)串行四線驅(qū)動(dòng)1602液晶程序

作者: 時(shí)間:2016-11-30 來源:網(wǎng)絡(luò) 收藏
#include "msp430g2553.h"

#define uchar unsigned char
#define uint unsigned int
#define RS_1 P1OUT|=BIT3;//輸入數(shù)據(jù)
#define RS_0 P1OUT&=~BIT3;//輸入指令
#define RW_1 P1OUT|=BIT4;//寫入指令或者數(shù)據(jù)
#define RW_0 P1OUT&=~BIT4;//從lcd里面讀取數(shù)據(jù)
#define EN_1 P1OUT|=BIT5;//讀取信息
#define EN_0 P1OUT&=~BIT5;//下降沿時(shí)候執(zhí)行指令
#define datt P2OUT;
uchar temp=0;
uchar table1[]={"hello"};
uchar table2[]={"hello"};

本文引用地址:http://m.butianyuan.cn/article/201611/323798.htm

/*.................................................
* 延時(shí)程序
.................................................. */

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

/*.................................................
* 忙信號(hào)檢查
.................................................. */

uchar chkbusy()
{
uchar busy;
P2OUT=0xf0;
EN_0;//讀取數(shù)據(jù)
RS_0;//輸入指令
RW_1;//寫入指令或者數(shù)據(jù)
EN_1;//讀取信息
busy=P2OUT&0x80;
delay(1);
EN_0;//下降沿執(zhí)行指令
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;
}

/*.................................................
* 寫數(shù)據(jù)
.................................................. */

void writedata(uchar dat)
{

//while(chkbusy()); //檢查忙信號(hào)
EN_0;
RS_1;
RW_0;
EN_1;
P2OUT=(dat&0xf0); //送高四位數(shù)據(jù)到P2口
delay(5);
EN_0;
delay(5);
EN_1;
P2OUT=(dat&0x0f)<<4; //送低四位數(shù)據(jù)到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,0x02);//數(shù)據(jù)指針清零
delay(5);
writecom(1,0x28);//
writecom(1,0x0c);//顯示光標(biāo)開及設(shè)置
writecom(1,0x06);//顯示光標(biāo)移動(dòng)設(shè)置
writecom(1,0x01);//顯示清屏
delay(10);
}

/*.................................................
* 在指定位置顯示一個(gè)字符,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++;
}
}

/*.................................................
* 主函數(shù)
.................................................. */

void main()
{

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

lcdinit();
//lcdcls();

P2OUT=0xff;

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



評(píng)論


技術(shù)專區(qū)

關(guān)閉