#include <msp430x54x.h>
//#define CPU_F ((double)8000000)//默认MCLK=1MHz
#define uint unsigned int
#define uchar unsigned char
/*******************************************************************************
p90=cs(RS);p91=sid(RW);p92=clk(EN);p93=psb(低电平选串口);p94=rst;(接高电平)
********************************************************************************/
#define LCD_RS BIT0 //LCD_RS(DI) -> P9.0
#define LCD_RS_DIR P9DIR
#define LCD_RS_LO P9OUT &= ~LCD_RS
#define LCD_RS_HI P9OUT |= LCD_RS
#define LCD_RW BIT1 //LCD_RW -> P9.1
#define LCD_RW_DIR P9DIR
#define LCD_RW_LO P9OUT &= ~LCD_RW
#define LCD_RW_HI P9OUT |= LCD_RW
#define LCD_EN BIT2 //LCD_EN -> P9.2
#define LCD_EN_DIR P9DIR
#define LCD_EN_LO P9OUT &= ~LCD_EN
#define LCD_EN_HI P9OUT |= LCD_EN
#define LCD_PSB BIT3 //LCD_CS1(PSB) -> P9.3
#define LCD_PSB_DIR P9DIR
#define LCD_PSB_LO P9OUT &= ~LCD_PSB
#define LCD_PSB_HI P9OUT |= LCD_PSB
#define LCD_RST BIT4 //LCD_RST -> P9.4
#define LCD_RST_DIR P9DIR
#define LCD_RST_LO P9OUT &= ~LCD_RST
#define LCD_RST_HI P9OUT |= LCD_RST
#define LCD_DATA_IN P8IN //并行数据输出/入口
#define LCD_DATA_OUT P8OUT
#define LCD_DATA_DIR P8DIR
void LCD_Delayt(uint t) //毫秒级延时子程序
{
uint i;
while(t--)
{
for(i=0;i<800;i++);
}
}
void LCD_CheckBusy(void) //忙检测
{
uchar Flag;
LCD_RS_LO;
LCD_RW_HI;
LCD_DATA_DIR = 0x00;
do
{
LCD_EN_HI;
Flag = LCD_DATA_IN;
LCD_EN_LO;
}
while(Flag & 0x80);
LCD_DATA_DIR = 0xFF;
}
void LCD_WriteComm(uchar wdata)// 写命令
{
LCD_CheckBusy();//忙检测
LCD_RS_LO;
LCD_RW_LO;
LCD_EN_LO;
LCD_EN_HI;
LCD_DATA_OUT = wdata;
LCD_EN_LO;
}
void LCD_WriteByte(uchar wdata)//写数据
{
LCD_CheckBusy(); //忙检测
LCD_RS_HI;
LCD_RW_LO;
LCD_EN_LO;
LCD_EN_HI;
LCD_DATA_OUT = wdata; //P8输出数据
LCD_EN_LO;
}
void LCD_SetXY(uchar X, uchar Y)//写坐标X、Y地址
{
switch(Y)
{
case 0:
LCD_WriteComm(0x80 + X);
break;
case 1:
LCD_WriteComm(0x90 + X);
break;
case 2:
LCD_WriteComm(0x88 + X);
break;
case 3:
LCD_WriteComm(0x98 + X);
}
}
/*
void LCD_WriteDEC(uchar X, uchar Y, uchar wdata) //第一种、要显示数据的位置和数据
{
LCD_SetXY(X,Y); //写坐标X、Y地址
LCD_WriteByte(wdata); //写数据wdata
}*/
void LCD_WriteString(uchar X, uchar Y, uchar *String)//第二种、要显示数据的位置和数据
{
uchar temp;
LCD_SetXY(X,Y);
temp = *String;
while(temp!=0)
{
LCD_WriteByte(temp);
temp = *(++String);
}
}
void LCD_Init(void) //LCD12864初始化
{
LCD_PSB_HI; //PSB=1 -> 并行模式
LCD_RST_HI;
LCD_Delayt(2);
LCD_RS_LO;
LCD_RW_LO;
LCD_EN_LO;
LCD_Delayt(2);
//正常状态
LCD_WriteComm(0x30); //基本指令操作
LCD_WriteComm(0x0c); //显示开,关光标
LCD_WriteComm(0x01); //清除LCD12864的显示内容
LCD_WriteComm(0x02); //地址归位
LCD_WriteComm(0x06); //游标加1
}
void diaply()//数据显示
{
LCD_WriteString(0,0," msp430f5438 ");//第一行显示aaa的数据
LCD_Delayt(1);
LCD_WriteString(0,1,"LCD12864并口液晶");//第二行第1个位置显示数据"这是第一行的!"
LCD_Delayt(1);
LCD_WriteString(0,2," 测试显示! ");//第三行第1个位置显示数据"这是第一行的!"
LCD_Delayt(1);
LCD_WriteString(0,3,"!!!!!!!!");//第四行第1个位置显示数据"这是第一行的!"
LCD_Delayt(1);
}
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P9DIR |=0xff;
P9OUT =0xff;
P8DIR |=0xff;
P8OUT =0xff;
LCD_Init(); //LCD12864初始化
diaply(); //数据显示
while(1);
}
此帖出自
小平头技术问答
把LCD初始化程序中的延时弄长一些试试
因为你51时候的晶振是M级的
而MSP430默认使用的DCO晶振,是K级的
所以你没有配置外部晶振的时候延时不够快的,LCD来不及反应
试一下,好了也告诉我一下
以上只是个人猜测,接触MSP430才2天
[ 本帖最后由 wgsxsm 于 2012-11-10 14:42 编辑 ]
一周热门 更多>