1247 views|0 replies

2015

Posts

0

Resources
The OP
 

MSP430F5529&LCD1602 Program [Copy link]

After a day of work, the board broke and could not display letters. I didn't find out until noon. I changed to a new board and spent an afternoon tinkering with it. It can be used now. In fact, the reference program is very well written. I simplified it and it works fine for me.

Code
LCD1602.c

#include <msp430.h>
#include <string.h>
#include <LCD1602.h>
#define CPU_F ((double)8000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
#define DataDir P3DIR
#define DataPort P3OUT
#define Busy 0x80
#define CtrlDir P1DIR
#define CLR_RS P1OUT&=~BIT3; //RS = P1.3
#define SET_RS P1OUT|=BIT3;
#define CLR_RW P1OUT&=~BIT4; //RW = P1.4
#define SET_RW P1OUT|=BIT4;
#define CLR_EN P1OUT&=~BIT5; //EN = P1.5
#define SET_EN P1OUT|=BIT5;
void Disp1Char(unsigned char data)
{
LCD1602_WriteDATA(data);
}
void DispStr(unsigned char *ptr)
{
unsigned char i,n;
n=strlen(ptr);
for (i=0;i<n;i++)
{
Disp1Char(ptr[i]);
}
}
void LCD1602_WriteCMD(unsigned char cmd)
{
CLR_EN;
CLR_RS; //指令
CLR_RW; //写
DataPort=cmd; //指令数据传到P0口待发送给LCD1602
delay_ms(1);
SET_EN; //LCD1602使能口
delay_ms(10);
CLR_EN; //产生下降沿
delay_ms(10);
}
void LCD1602_WriteDATA(unsigned char Data)
{
DataPort=Data;
SET_RS;
CLR_RW;
SET_EN;
CLR_EN;
delay_ms(10);
}
void LCD1602_Initi()
{
CtrlDir |= 0x38; //控制线端口设为输出状态
DataDir = 0xff;
LCD1602_WriteCMD(0x38); // 置功能,8位总线,双行显示,显示5X7的点阵字符
LCD1602_WriteCMD(0x0f); // 显示开关控制,开显示, 有光标,闪烁
LCD1602_WriteCMD(0x06); // 光标和显示位置设置, 光标移动方向右移,屏幕上所有文字不动
LCD1602_WriteCMD(0x01); // 清显示,指令码01H,光标复位到地址00H位置
delay_ms(10);
}

LCD1602.h

/*
* LCD1602.h
*
* Created on: June 3, 2018
* Author: Sunnl
*/

#ifndef LCD1602_H_
#define LCD1602_H_
#include <msp430.h>
void Disp1Char(unsigned char data);
void DispStr(unsigned char *ptr);
void LCD1602_WriteCMD(unsigned char cmd);
void LCD1602_WriteDATA(unsigned char Data);
void LCD1602_Initi();
#endif
/* LCD1602_H_ */

main.c

#include <msp430.h>
#include "LCD1602.h"
unsigned char s[]="LCD1602Test";
int main(void)
{
WDTCTL = WDTPW | WDTHOLD;
LCD1602_Initi();
LCD1602_WriteCMD(0x80);
DispStr(s);
return 0;
}

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>
Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list