将程序烧进去,可是液晶屏就是不显示,求大神告知这是怎么回事,数据输出口是P3,
单片机用的MSP430F5529,而且编译也没有问题
#include<msp430.h>
#define CLR_RS P2OUT&=~BIT0
#define SET_RS P2OUT|=BIT0
#define CLR_RW P2OUT&=~BIT2
#define SET_RW P2OUT|=BIT2
#define CLR_EN P7OUT&=~BIT4
#define SET_EN P7OUT|=BIT4
#define uchar unsigned char
unsigned char *jieshu = "This is the end!";
void delay_1ms(void);
void delay_nus(unsigned int n);
void delay_nms(unsigned int n);
void check_busy(void);
void write_command(unsigned char com,unsigned char chk);
void write_data(unsigned char dat);
void LCD_ini
tial(void);
void DispStr(uchar x,uchar y,uchar *ptr);
void DispNChar(uchar x,uchar y, uchar n,uchar *ptr) ;
void LocateXY(uchar x,uchar y);
void DisponeChar(uchar x,uchar y,uchar data);
void delay_nus(unsigned int n)
{
unsigned int i;
for (i=0;i<n;i++)
delay_nus(1);
}
/************************************
1ms延时函数
****************************************/
void delay_1ms(void)
{
unsigned int i;
for (i=0;i<1140;i++);
}
/*****************************************
N ms延时函数
******************************************/
void delay_nms(unsigned int n)
{
unsigned int i=0;
for (i=0;i<n;i++)
delay_1ms();
}
/*检测忙状态*/
void check_busy(void)
{
P3DIR|=0X00;//设置P3为输入
CLR_EN ;
__no_operation();
CLR_RS;
__no_operation();
SET_RW;
__no_operation();
SET_EN;
while(P3IN&0x80);
CLR_EN;
P3DIR|=0Xff;//将P3设置为输出
}
/*写命令*/
void write_command(unsigned char com,unsigned char chk)
{
if(chk)
check_busy();
CLR_EN;
CLR_RS;
__no_operation();
CLR_RW ;
__no_operation();
P3OUT|=com;
__no_operation();
SET_EN;
__no_operation();
CLR_EN;
}
/*写数据*/
void write_data(unsigned char dat)
{
check_busy();
CLR_EN ;
__no_operation();
SET_RS;
__no_operation();
CLR_RW ;
__no_operation();
P3OUT=dat;
__no_operation();
SET_EN;
__no_operation();
CLR_EN ;
}
void LCD_initial(void)
{
P2DIR|=BIT0+BIT2;
P7DIR|=BIT4;
P3DIR|=0xff;
delay_nms(15);
write_command(0x38,0);
delay_nms(5);
write_command(0x38,0);
delay_nms(5);
write_command(0x38,0);
delay_nms(5);
write_command(0x38,1);
write_command(0x08,1);//关闭显示
write_command(0x01,1);//清屏
write_command(0x06,1);//光标右移
write_command(0x0C,1);//开整体显示,光标关,无黑块
}
void string(unsigned char ad,unsigned char *s)
{
write_command(ad,1);
while(*s>0)
{
write_data(*s++);
delay_nms(100);
}
}
void main()
{
WDTCTL = WDTPW + WDTHOLD;
LCD_initial();
while(1)
{
string(0x81,"Happy New Year");
Delay1ms(100);
string(0xC1,"Welcome to HIT");
Delay1ms(100);
write_command(0x01,1);
}
}
一周热门 更多>