5回答

0收藏

[原创] 【Energia开发环境】MSP430 LAUNCHPAD学习笔记7--1602液晶显示

TI TI 5720 人阅读 | 5 人回复 | 2014-01-17

本帖最后由 qinkaiabc 于 2014-1-17 13:11 编辑

【Energia开发环境】MSP430 LAUNCHPAD学习笔记7--4位驱动1602液晶显示
材料:
· MSP-EXP430G2 553LaunchPad
· LCD1602字符液晶
1602LCD主要技术参数:
显示容量为16×2个字符;
芯片工作电压为4.5~5.5V;
工作电流为2.0mA(5.0V);
模块最佳工作电压为5.0V;
字符尺寸为2.95×4.35(W×H)mm。
MSP430 LAUNCHPAD提供3.57V的电压也是能够正常驱动1602的。
1602液晶接口引脚定义 :
除了1脚(VSS)2脚(VDD)需要接外,15脚和16脚也需要接正负极,3号脚最好接GND,不接的话,会看不到显示的字。
4位接法的硬件连接图:
源程序:
/*******************************************************************
  1602液晶显示
  【Energia开发环境】MSP430 LAUNCHPAD学习笔记7--1602液晶显示
   Autor: qinkaiabc
   *  液晶1602.c--4线驱动
   *  Created on: 2013-7-27
   *  Author: Qinkai
   *  P2_0 -> D4
   *  P2_1 -> D5
   *  P2_2 -> D6
   *  P2_3 -> D7
   *  P2_5 -> EN
   *  P2_4 -> RS
   *  VO(VL) ->GND
   *  RW  -> GND
********************************************************************/
int D4 = P2_0;
int D5 = P2_1;
int D6 = P2_2;
int D7 = P2_3;
int RS = P2_4;
int EN = P2_5;
//引脚定义,从头文件可知
int a[6] = { 8, 9, 10, 11,12,13};
void LCD_Command_Write(int command)
{
  int i,temp;
  digitalWrite( RS,LOW);
  digitalWrite( EN,LOW);
  delayMicroseconds(1);
  digitalWrite( EN,HIGH);
  temp = command & 0xf0;
  for(i=a[3];i>7;i--)  //写高四位
  {
     digitalWrite(i,temp & 0x80);
     temp <<= 1;
  }
  digitalWrite( EN,HIGH);
  delayMicroseconds(1);
  digitalWrite( EN,LOW);  
  temp=(command & 0x0f) << 4;
  for(i=a[3];i>7;i--)  //写低四位
  {
     digitalWrite(i,temp & 0x80);
     temp <<= 1;
  }
  digitalWrite( EN,HIGH);
  delayMicroseconds(1);
  digitalWrite( EN,LOW);
}
void LCD_Data_Write(int dat)
{
  int i,temp;
  digitalWrite( RS,HIGH);
  digitalWrite( EN,LOW);
  delayMicroseconds(1);
  digitalWrite( EN,HIGH);
  temp = dat & 0xf0;
  for(i=a[3];i>7;i--)  //写高四位
  {
     digitalWrite(i,temp & 0x80);
     temp <<= 1;
  }
  digitalWrite( EN,HIGH);
  delayMicroseconds(1);
  digitalWrite( EN,LOW);

  temp=(dat & 0x0f) << 4;
  for(i=a[3];i>7;i--)  //写低四位
  {
     digitalWrite(i,temp & 0x80);
     temp <<= 1;
  }
  digitalWrite( EN,HIGH);
  delayMicroseconds(1);
  digitalWrite( EN,LOW);
}
//显示字符
void LCD_write_int(unsigned int x,unsigned int y,unsigned int data)
{
  unsigned int address;  //写地址
  if (y == 0)
  {
    address = 0x80 + x;
  }
  else
  {
    address = 0xc0 + x;
  }
  LCD_Command_Write( address);
  delayMicroseconds(1);
  LCD_Data_Write(data);
}
//LCD在任意位置写字符串
//列x=0~15,行y=0,1
void LCD_write_string(unsigned int x,unsigned int y,char *s)
{
  unsigned int address;  //写地址
  if (y == 0)
  {
    address = 0x80 + x;
  }
  else
  {
    address = 0xc0 + x;
  }
  LCD_Command_Write( address);
  delayMicroseconds(1);
  while (*s) // 显示字符
  {
    LCD_Data_Write( *s );
    delayMicroseconds(1);
    s++;
  }
}
//lcd初始化程序
void LCD1602_Init()
{
  int i=0;
  for(i=8;i<14;i++)//初始化P2引脚为输出
  {
    pinMode(i,OUTPUT);
  }
  delay(100);
  LCD_Command_Write(0x28);
  delay(50);
  LCD_Command_Write(0x06);
  delay(50);
  LCD_Command_Write(0x0c);
  delay(50);
  LCD_Command_Write(0x80);
  delay(50);
  LCD_Command_Write(0x01);
  delay(50);
}
void setup()
{
  LCD1602_Init();

}
void loop()
{
  LCD_Command_Write(0x01);
  delay(50);
  LCD_write_string(0,0,"Hello! EEWORLD!");
  LCD_write_string(0,1,"MSP430 LAUNCHPAD");
  delay(5000);
  LCD_write_string(0,0,"EnergiaforMSP430");

  delay(5000);
}
从头文件中看出MSP430 Launch Pad 的管脚定义如下:
/*************************************************************************
  *        pins_energia.h
  *        Energia core files for MSP430
  *                Copyright (c) 2012 Robert Wessels. All right reserved.
  *     Contribution: Rei VILO
//                      +-\/-+
//               VCC   1|    |20  GND
//         (A0)  P1.0  2|    |19  XIN
//         (A1)  P1.1  3|    |18  XOUT
//         (A2)  P1.2  4|    |17  TEST
//         (A3)  P1.3  5|    |16  RST#
//         (A4)  P1.4  6|    |15  P1.7  (A7) (SCL) (MISO) depends on chip
//         (A5)  P1.5  7|    |14  P1.6  (A6) (SDA) (MOSI)
//               P2.0  8|    |13  P2.5
//               P2.1  9|    |12  P2.4
//               P2.2 10|    |11  P2.3
//                      +----+
// Pin names based on the silkscreen
static const uint8_t P1_0 = 2;
static const uint8_t P1_1 = 3;
static const uint8_t P1_2 = 4;
static const uint8_t P1_3 = 5;
static const uint8_t P1_4 = 6;
static const uint8_t P1_5 = 7;
static const uint8_t P2_0 = 8;
static const uint8_t P2_1 = 9;
static const uint8_t P2_2 = 10;
static const uint8_t P2_3 = 11;
static const uint8_t P2_4 = 12;
static const uint8_t P2_5 = 13;
static const uint8_t P1_6 = 14;
static const uint8_t P1_7 = 15;
static const uint8_t P2_7 = 18;
static const uint8_t P2_6 = 19;
static const uint8_t RED_LED = 2;
static const uint8_t GREEN_LED = 14;
static const uint8_t PUSH2 = 5;
static const uint8_t TEMPSENSOR = 10; // depends on chip
  ***********************************************************************/
所以在上面的初始化引脚和写命令及写数据,可以直接通过对数字操作。
By qinkaiabc


_1602.zip (1.16 KB, 下载次数: 52)


【Energia开发环境】MSP430 LAUNCHPAD学习笔记7--1602液晶显示.pdf (551.25 KB, 下载次数: 59)


1602.pdf (233 KB, 下载次数: 26)

1602手册.pdf (634.17 KB, 下载次数: 20)

SMC1602A.pdf (255.88 KB, 下载次数: 14)



这个世界成功人的总是少数,我们都只是平凡的人,我们需要有一种平凡且进取的心态去生活,不要期望有多少付出就一定有多少回报,相信没有付出就没有回报就可以了。
分享到:
回复

使用道具 举报

回答|共 5 个

倒序浏览

沙发

木林森X

发表于 2014-1-17 14:21:01 | 只看该作者

跟楼上一起看看      
板凳

brucehelen

发表于 2014-1-17 15:52:21 | 只看该作者

楼主,你上面那个图用什么软件画的?非常漂亮!
地板

夏洛克

发表于 2014-1-17 16:03:36 | 只看该作者

bruce_helen 发表于 2014-1-17 15:52
楼主,你上面那个图用什么软件画的?非常漂亮!

http://fritzing.org/home/
这个世界成功人的总是少数,我们都只是平凡的人,我们需要有一种平凡且进取的心态去生活,不要期望有多少付出就一定有多少回报,相信没有付出就没有回报就可以了。
5#

brucehelen

发表于 2014-1-17 19:18:12 | 只看该作者

qinkaiabc 发表于 2014-1-17 16:03
http://fritzing.org/home/

不错的软件
6#

sacq12

发表于 2014-1-21 16:14:06 | 只看该作者

qinkaiabc 发表于 2014-1-17 16:03
http://fritzing.org/home/

这个好~~~
您需要登录后才可以回帖 注册/登录

本版积分规则

学生
1421 积分
113 主题
+ 关注
关闭

站长推荐上一条 /3 下一条