4932 views|9 replies

6366

Posts

4929

Resources
The OP
 

MSP430 MCU simulation example 14-LCD1602 liquid crystal display characters based on Proteus [Copy link]

 



This content is originally created by EEWORLD forum user tiankai001. If you need to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source. 1. Task requirements
Use the MSP30F247 microcontroller to drive the LCD1602 liquid crystal to display two lines of characters: the first line displays "lao ma shi tu mcu", and the second line displays "msp430f247 study".
2. Hardware circuit
The hardware circuit is shown in the figure below. Select the P2 port of MSP430F247 microcontroller to connect the data lines D0~D7 of LCD1602, P3.0, P3.1, and P3.2 are respectively connected to the enable EN port, read/write RW port, and register RS port of LCD1602 to generate the timing required by LCD1602.
3. Programming
//main.c
#include "msp430f247.h"
#include "stdlib.h"
#include "string.h"
/************************************************Software delay, clocked at 1M**********************/
#define CPU_F1 ((double)1000000)
#define delay_us1M(x) __delay_cycles((long)(CPU_F1*(double)x/1000000.0))
#define delay_ms1M(x) __delay_cycles((long)(CPU_F1*(double)x/1000.0))
/****************************************************************************/
#define SET_RS P3OUT |= BIT2
#define RST_RS P3OUT &= ~BIT2
#define SET_RW P3OUT |= BIT1
#define RST_RW P3OUT &= ~BIT1
#define SET_E P3OUT |= BIT0
#define RST_E P3OUT &= ~BIT0
//
const unsigned char Table1[]={"lao ma shi tu mcu"};
const unsigned char Table2[]={"msp430f247 study"};
void write_com(unsigned char com);//Write command function
void write_dat(unsigned char dat);//Write data function
/****************************************************
Function name: main function
Function: LCD1602 liquid crystal display character
Input parameters: None
Output parameters: None
Description:
Author: Lao Ma Shi Tu Microcontroller
Date: January 6, 2018
********************************************************/
main()
{
unsigned char i;
WDTCTL = WDTPW + WDTHOLD;//Turn off the watchdog
P2DIR=0xff;//Port initialization
P3DIR=BIT0+BIT1+BIT2;
RST_E;
write_com(0x38);//Set 16*2 display, 5*7 dot matrix, 8-bit data interface
delay_ms1M(5);
write_com(0x01);//Display clear screen
delay_m s1M(5);
write_com(0x0c);//Display switch, cursor setting
delay_ms1M(5);
write_com(0x06);//Display switch, cursor setting
delay_ms1M(5);
write_com(0x80);//Data pointer setting, first line display
delay_ms1M(5);
for(i=0;i程序首先对端口进行初始化,将单片机与液晶LCD1602相连的端口设置为输出端口,并对液晶进行初始化设置。在液晶的程序设计中,用了一些宏定义实现对液晶RS,RW,EN等引脚的高低电平的控制,其顺序是按照液晶显示时序设计的。
[color=rgb(34,' 34,="" <="" align][align="left]{
write_dat(Table1);
}
write_com(0x80+0x40);//数据指针设置,第二行显示
delay_ms1M(5);
for(i=0;i<sizeof(Table2);i++)
{
write_dat(Table2);
}
while(1)
{
}
}
void" char="" com)[="" dat)[="" div="" write_com(unsigned="" write_dat(unsigned="">
This post was last edited by 13432812441 on 2018-2-26 17:17 I found a small error in the original poster's program, write_dat(Table1); should be changed to write_dat( Table1 ); write_dat( Table2); should be changed to write_dat( Table2 );

I don't know why I couldn't type the brackets "[]" in my reply just now, so it's the same as not replying at all. I'm really sorry. However, there are indeed two sentences in the original poster's program that are missing brackets "[]"

13432812441 Posted on 2018-2-26 16:38 I don't know why I can't type the brackets "[]" in my reply just now, so it's the same as not replying. I'm really sorry. But there are two sentences in the original poster's program...[/quote] Sorry, where is the missing "[]", please correct me. This program can run normally when I simulate it

tiankai001 posted on 2018-2-27 08:58 Sorry, I am missing a “[]” somewhere. Please correct me. This program can run normally when I simulate it[/quote] There are two small errors: (1) write_dat(Table1); should be changed to write_dat(Table1[ i ]); (2) write_dat(Table2); should be changed to write_dat(Table2[ i ]);

13432812441 Published on 2018-2-27 12:08 There are two small errors: (1) write_dat(Table1); should be changed to write_dat(Table1[ i ]); (2) write_dat(Table2); should be...[/quote] Thank you for pointing out the error. I carefully compared my source code and found that it was correct. I don’t know why it changed after I pasted it out.

[quote]tiankai001 posted on 2018-2-27 12:23 Thank you for pointing out the error. I carefully compared my source code and found that it was correct. I don’t know why it changed after pasting it out.
In fact, when I typed the brackets “[]”, I also found that they were clearly typed, but they disappeared after publishing. Later, I added a space character in the brackets and it was fixed
[quote]13432812441 Published on 2018-2-27 22:06 Actually, when I was typing the brackets “[]”, I also found that they were clearly typed, but they disappeared after posting. Later, I added a space character inside the brackets...
Oh, so that’s how it is. I learned another trick. Thank you very much
[quote]tiankai001 posted on 2018-2-28 08:46 Oh, so that's how it is. I learned another trick. Thank you very much
You're welcome. I should say thank you very much for the information shared by the host.
gangxie

MSP430 MCU simulation example 14-LCD1602 liquid crystal display characters based on Proteus


This post is from Microcontroller MCU

Latest reply

gangxie  Details Published on 2018-3-26 21:30
 

17

Posts

0

Resources
2
 
This post was last edited by 13432812441 on 2018-2-26 17:17 I found a small error in the original poster's program, write_dat(Table1); should be changed to write_dat( Table1 ); write_dat( Table2); should be changed to write_dat( Table2 );

Snipaste_2018-02-26_16-17-24.png (15.32 KB, downloads: 0)

Snipaste_2018-02-26_16-17-24.png
This post is from Microcontroller MCU
 
 

17

Posts

0

Resources
3
 
I don't know why I couldn't type the brackets "[]" in my reply just now, so it's the same as not replying at all. I'm really sorry. However, there are indeed two sentences in the original poster's program that are missing brackets "[]"
This post is from Microcontroller MCU

Comments

Sorry, I'm wondering where the "[]" is missing. Please correct me. This program can run normally when I simulate it.  Details Published on 2018-2-27 08:58
 
 
 

6366

Posts

4929

Resources
4
 
13432812441 Posted on 2018-2-26 16:38 I don't know why I can't type the brackets "[]" in my reply just now, so it's the same as not replying. I'm really sorry. But there are two sentences in the original poster's program...
Sorry, where is the missing "[]", please correct me. This program can run normally when I simulate it
This post is from Microcontroller MCU

Comments

There are two minor errors: (1) write_dat(Table1); should be changed to write_dat(Table1[ i ]); (2) write_dat(Table2); should be changed to write_dat(Table2[ i ]);  Details Published on 2018-2-27 12:08
 
 
 

17

Posts

0

Resources
5
 
tiankai001 posted on 2018-2-27 08:58 Sorry, I am missing a “[]” somewhere. Please correct me. This program can run normally when I simulate it
There are two small errors: (1) write_dat(Table1); should be changed to write_dat(Table1[ i ]); (2) write_dat(Table2); should be changed to write_dat(Table2[ i ]);
This post is from Microcontroller MCU

Comments

Thank you for pointing out the error. I carefully checked my source code and found that it was correct. I don't know why it changed after pasting it out.  Details Published on 2018-2-27 12:23
 
 
 

6366

Posts

4929

Resources
6
 
13432812441 Published on 2018-2-27 12:08 There are two small errors: (1) write_dat(Table1); should be changed to write_dat(Table1[ i ]); (2) write_dat(Table2); should be...
Thank you for pointing out the error. I carefully compared my source code and found that it was correct. I don’t know why it changed after I pasted it out.
This post is from Microcontroller MCU

Comments

In fact, when I was typing the brackets "[]", I found that I had typed them, but they disappeared after publishing. Later, I added a space character inside the brackets and it worked.  Details Published on 2018-2-27 22:06
 
 
 

17

Posts

0

Resources
7
 
tiankai001 posted on 2018-2-27 12:23 Thank you for pointing out the error. I carefully compared my source code and found that it was correct. I don’t know why it changed after pasting it out.
In fact, when I typed the brackets “[]”, I also found that they were clearly typed, but they disappeared after publishing. Later, I added a space character in the brackets and it was fixed
This post is from Microcontroller MCU

Comments

Oh, that's how it is. I learned a new trick. Thank you very much.  Details Published on 2018-2-28 08:46
 
 
 

6366

Posts

4929

Resources
8
 
13432812441 Published on 2018-2-27 22:06 Actually, when I was typing the brackets “[]”, I also found that they were clearly typed, but they disappeared after posting. Later, I added a space character inside the brackets...
Oh, so that’s how it is. I learned another trick. Thank you very much
This post is from Microcontroller MCU

Comments

You're welcome. I should say thank you very much for sharing the information.  Details Published on 2018-2-28 11:24
 
 
 

17

Posts

0

Resources
9
 
tiankai001 posted on 2018-2-28 08:46 Oh, so that's how it is. I learned another trick. Thank you very much
You're welcome. I should say thank you very much for the information shared by the host.
This post is from Microcontroller MCU
 
 
 

24

Posts

0

Resources
10
 
gangxie
This post is from Microcontroller MCU
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

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