I checked a lot on the Internet; many people said that it would be easy to use after downloading it, but it was useless. I will write this for myself to read later. It is not very standardized, just for reference. It should be OK to download it, but it is very dark under 3.3V power supply. And 2553 only has a few IO ports after all. If conditions permit, you can waste it like this. The data port of this code is transmitted through P1, but the P1 port has various other commonly used functions. So if you really need to use it, it is better to use P2 as the data port. Just change the port in the code. But a word of advice: be sure to check the IO configuration carefully in the manual. Although there is no big problem in this program
First attach the code directly:
# include "msp430G2553.h"
# define uchar unsigned char
# define uint unsigned int
# define LCD1602_RS_H P2OUT|=BIT0
# define LCD1602_RS_L P2OUT&=~BIT0
# define LCD1602_RW_H P2OUT|=BIT1
# define LCD1602_RW_L P2OUT&=~BIT1
# define LCD1602_EN_H P2OUT|=BIT2
# define LCD1602_EN_L P2OUT&=~BIT2
/****************************************************************************
Function name: Delay_Nms
Function: Delay Nms (the default internal DCO seems to be 1MHZ)
Function parameters: n
Function return value: None
Additional note: This delay function is not accurate. It is roughly estimated from the time it takes to execute the instruction.
****************************************************************************/
void Delay_Nms(uint n)
{
uint i,j;
for(i=250;i>0;i--)
for(j=n;j>0;j--);
}
/****************************************************************************
Function name: Write_1602_Cmd
Function: Write a byte of instruction to 1602
Function parameter: uchar: Cmd
Function return value: None
Additional note: The level of reading the timing diagram is still far from enough and the understanding is far from enough. When writing, the following comments are added
The result is that it just doesn’t show up!!!
****************************************************************************/
void Write_1602_Cmd(uchar Cmd)
{
LCD1602_RS_H; //RS is low write instruction
LCD1602_RW_H;
LCD1602_EN_L;
LCD1602_RS_L;
LCD1602_RW_L;
P1OUT=Cmd;
Delay_Nms(5);
LCD1602_EN_H;
Delay_Nms(5);
LCD1602_EN_L;
//LCD1602_RW_L;
//LCD1602_RS_H;
}
/****************************************************************************
Function name: Write_1602_Data
Function: Write one byte of data to 1602
Function parameters: uchar: Data
Function return value: None
Additional note: The level of reading the timing diagram is still far from enough and the understanding is far from enough. When writing, the following comments are added
The result is that it just doesn’t show up!!!
****************************************************************************/
void Write_1602_Data(uchar Data)
{
LCD1602_RS_L;
LCD1602_RW_L;
LCD1602_EN_L;
LCD1602_RS_H;
LCD1602_RW_L;
P1OUT=Data;
Delay_Nms(5);
LCD1602_EN_H;
Delay_Nms(5);
LCD1602_EN_L;
//LCD1602_RS_L;
//LCD1602_RW_L;
}
/****************************************************************************
Function name: Init_1602
Function: Initialize 1602 and IO ports
Function parameters: None
Function return value: None
Additional note: Be sure to read the IO configuration carefully in the manual
****************************************************************************/
void Init_1602()
{
P1DIR|=0xff;
P1SEL=0;
P1SEL2=0;
P2DIR|=BIT0+BIT1+BIT2;
P2SEL&=~(BIT0+BIT1+BIT2); //Default is 0, optional
P2SEL2&=~(BIT0+BIT1+BIT2);//Same as above, no need to write, just check the manual IO configuration
Write_1602_Cmd(0x38);
Delay_Nms(5);
Write_1602_Cmd(0x0c);
Delay_Nms(5);
Write_1602_Cmd(0x06);
Delay_Nms(5);
Write_1602_Cmd(0x01);
}
void main()
{
WDTCTL = WDTPW + WDTHOLD; // Often forget to turn off the watchdog
Heat_1602();
while(1)
{
Write_1602_Cmd(0x80); //Display screen command writing function
Write_1602_Data('2'); // Display screen data writing function
}
}
Previous article:MSP430G2253 generates PWM with adjustable duty cycle
Next article:msp430 button control LED light
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Today's live broadcast: Battery management chip solution design and precautions
- [Repost] 7 PCB layout principles, good PCB design depends on it
- It’s terrible. Two manufacturers in the PCB industry are engaged in a price war. Did you get any benefits yesterday?
- 【McQueen Trial】Python Programming (4)
- Crazy Shell AI open source drone interruption (key detection)
- Data flow modeling
- [Top Micro Smart Display Screen Review] 4. Network port remote update and communication function test and questions
- IAR for MSP430 Two methods of adding custom header files
- CC2640R2F supports Alibaba Cloud Link IoT platform
- [Mill MYB-YT507 development board trial experience] + unboxing experience