MSP430G2553 1602 display characters

Publisher:oplndctkl出Latest update time:2018-07-14 Source: eefocusKeywords:MSP430G2553 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

  }

}


Keywords:MSP430G2553 Reference address:MSP430G2553 1602 display characters

Previous article:MSP430G2253 generates PWM with adjustable duty cycle
Next article:msp430 button control LED light

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号