This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430G2553 P2 high 4 bit connect LCD1602

Other Parts Discussed in Thread: MSP430G2553

MSP430G2553 20pins 4 LCD1602显示

作为初学者,在过去的一周反复查资料,有所小成如下。

  1. G2553可怜的GPIO口数,计划使用P2高四位,但是实用中发现P2.6和P2.7多功能引脚。(Pin19 is P2.6, P18 is P2.7.)

计划使用P1.6 and P1.7 as I2C communication port.

  1. 改来改去最终发现P2.6和P2.7无法使用,其默认功能选择晶振XIN和XOUT,

若要使用它们的IO功能,需将P2SEL.6和P2SEL.7置零。

在GPIO初始化里将它们配置为普通IO口之后,果然能正常显示数据了。

l  P2SEL&=~(BIT6+BIT7);// Using the second functions;

l  P2SEL2&=~(BIT6+BIT7);//Using the second functions;

 

  1. Clock Configuration;

TI MCU MSP430 单片机工作的系统时钟被分为了MCLK、SMCLK 和ACLK 三个,可以根据需要关闭其中的一个几个或全部。

#include <INTRINSICS.h>

__delay_cycles(1000000); //与CPU时钟相关的长延时

l  Do you know why 32768 Hz is a standard?

It is because that number is 215

 

 

 

LCD.c.txt
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* LCD.c
*
* Created on: 2020��3��25��
* Author: Mikejin
*/
#include"lcd.h"
#include "msp430g2553.h"
#include <intrinsics.h>
//����////////////////////////////////////////////////////////////////////
#define LCD_EN_PORT P1OUT//����2��Ҫ��Ϊͬһ����
#define LCD_EN_DDR P1DIR
#define LCD_RS_PORT P1OUT//����2��Ҫ��Ϊͬһ����
#define LCD_RS_DDR P1DIR
#define LCD_DATA_PORT P2OUT //����3��Ҫ��Ϊͬһ����
#define LCD_DATA_DDR P2DIR //һ��Ҫ�ø�4λ
#define LCD_RS BIT2
#define LCD_EN BIT1
//#define LCD_DATA BIT0|BIT1|BIT2|BIT3|BIT4|BIT5|BIT6|BIT7 //8λ����������ģʽʱʹ��
#define LCD_DATA BIT4|BIT5|BIT6|BIT7 //4λ����������ģʽʱʹ��
////Ԥ�����//////////////////////////////////////////////////////////////////
//LCDҺ����������///////////////////////////////////////////////////////////////
//LCD1602Һ����ʼ��
void LCD_init(void)
{
P2SEL&=~(BIT6+BIT7);// Using the second functions;
P2SEL2&=~(BIT6+BIT7);//Using the second functions;
delay_nms(15);
LCD_DATA_DDR|=LCD_DATA; //���ݿڷ���Ϊ���
LCD_EN_DDR|=LCD_EN; //����EN�������
LCD_RS_DDR|=LCD_RS; //����RS�������
delay_1ms(); //��4�в�Ҫ�ģ��������û��ʾ
// LCD_write_command(0x38); //8λ���ݽӿ�ʱ��ʹ�����У��������û��ʾ
LCD_write_command(0x33); //4λ���ݽӿ�ʱ��ʹ�����У��������û��ʾ
delay_1ms(); //
// LCD_write_command(0x38); //8λ���ݽӿ�ʱ��ʹ�����У��������û��ʾ
LCD_write_command(0x32); //4λ���ݽӿ�ʱ��ʹ�����У��������û��ʾ
delay_1ms();
// LCD_write_command(0x38); //8λ���ݽӿ�ʱ��ʹ�����У��������û��ʾ
delay_1ms();
// LCD_write_command(0x38); //8λ���ݽӿ�
LCD_write_command(0x2c); //4λ���ݽӿ�
delay_1ms();
LCD_write_command(0x0c); //��ʾ��
delay_1ms();
LCD_write_command(0x01); //����
delay_1ms();
LCD_write_command(0x06);
}
//Һ��ʹ��
void LCD_en_write(void)
{
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
LCD.h.txt
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
* LCD.h
*
* Created on: 2020��3��25��
* Author: Mikejin
*/
#ifndef LCD_H_
#define LCD_H_
void LCD_init(void);
void LCD_en_write(void);
void LCD_write_command(unsigned char command);
void LCD_write_data(unsigned char data);
void LCD_set_xy (unsigned char x, unsigned char y);
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);
void LCD_write_char(unsigned char X,unsigned char Y,unsigned char data);
void delay_1ms(void);
void delay_nus(unsigned int n);
void delay_nms(unsigned int n);
#endif /* LCD_H_ */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
main.c.txt
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**************************************************
* LCD1602 Display
* Description: P2 High 4 Bits for LCD1602 and P1.6 and P1.7 for I2C integrated another programmer.
* LCD1602 The first line showing "Hello!LCD1602D"
* LCD1602 The Second line showing "123456789abcdefg"
*
* Date��2020��4��12�յ��Գɹ�������������Ҫ����ΪLCD��ʼ����
*
* Ӳ����·��MSP430G2553 20pins
* Ӳ�����ӣ�
*
* MSP430��LCD������Ϣ
* LCD1602��4λ�ӿڣ���ʹ��D4-D7���ݿڣ�D0-D3������MCU
* PIN1 --> ��
* PIN2 --> VCC��һ��Ҫ��+5V��
* PIN3 -->����ʱ���գ�ʵ�ʵ�· 2K����-->�� (һ��Ҫ�Ӻã�����û���κ���ʾ)
* PIN4 --> RS --> P1.2
* PIN5 --> R/W --> GND
* PIN6 --> EN --> P1.1
* PIN7 --> D0���� * PIN8 --> D1���� * PIN9 --> D2���� * PIN10 --> D3����
* PIN11 --> D4 --> P2.4
* PIN12 --> D5 --> P2.5
* PIN13 --> D6 --> P2.6
* PIN14 --> D7 --> P2.7
* PIN15 --> VCC��һ��Ҫ��+5V�������Ҫ������Բ���)
* PIN16 --> ��
* ��������MSP430FETȫϵ��JTAG������
* ��������� CCS9.3 ����
**************************************************/
#include "msp430g2553.h"
#include <intrinsics.h>
#include"lcd.h"
void main()
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog
LCD_init();
delay_1ms();
while(1)
{
LCD_write_string(1,0,"Hello!LCD1602D");
delay_1ms();
LCD_write_string(0,1,"123456789abcdefg");
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Summary.docx