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
Recommended ReadingLatest update time:2024-11-22 21:52
- Popular Resources
- Popular amplifiers
- Single-chip microcomputer C language programming and simulation
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
- stm32+lcd1602 example
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Why is the larger OLED12864 so expensive?
- How to make technical requirements for hardware filters
- Can the adding circuit composed of the reverse amplifier circuit work under the condition of single power supply?
- [Mill MYB-YT507 development board trial experience] i2c driver
- STM8 Chinese Reference Manual
- Help with "SIM800C package - semi-circular arc problem"
- GD32L233C Sine Wave Generator
- [Watch the Power Supply Seminar and Win a Prize] A simple method to easily design AC-DC front-end modules
- Fixed-point programming of DSP floating-point calculation
- 【McQueen Trial】+Building Development Environment