查看: 4604|回复: 5

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

[复制链接]
  • TA的每日心情
    无聊
    2014-5-18 22:32
  • 签到天数: 257 天

    连续签到: 1 天

    [LV.8]以坛为家I

    发表于 2014-1-17 13:09:34 | 显示全部楼层 |阅读模式
    分享到:
    本帖最后由 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液晶接口引脚定义 :
    引脚说明.PNG
    除了1脚(VSS)2脚(VDD)需要接外,15脚和16脚也需要接正负极,3号脚最好接GND,不接的话,会看不到显示的字。
    4位接法的硬件连接图:
    接线图.PNG
    源程序:
    /*******************************************************************
      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
      ***********************************************************************/
    所以在上面的初始化引脚和写命令及写数据,可以直接通过对数字操作。
    捕获.JPG
    By qinkaiabc


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

    使用道具 举报

  • TA的每日心情
    开心
    2016-8-4 10:56
  • 签到天数: 242 天

    连续签到: 1 天

    [LV.8]以坛为家I

    发表于 2014-1-17 14:21:01 | 显示全部楼层
    跟楼上一起看看      
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    2015-10-8 09:49
  • 签到天数: 430 天

    连续签到: 1 天

    [LV.9]以坛为家II

    发表于 2014-1-17 15:52:21 | 显示全部楼层
    楼主,你上面那个图用什么软件画的?非常漂亮!
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    无聊
    2014-5-18 22:32
  • 签到天数: 257 天

    连续签到: 1 天

    [LV.8]以坛为家I

     楼主| 发表于 2014-1-17 16:03:36 | 显示全部楼层
    bruce_helen 发表于 2014-1-17 15:52
    楼主,你上面那个图用什么软件画的?非常漂亮!

    http://fritzing.org/home/
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    2015-10-8 09:49
  • 签到天数: 430 天

    连续签到: 1 天

    [LV.9]以坛为家II

    发表于 2014-1-17 19:18:12 | 显示全部楼层
    qinkaiabc 发表于 2014-1-17 16:03
    http://fritzing.org/home/

    不错的软件
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2019-7-13 19:58
  • 签到天数: 1818 天

    连续签到: 1 天

    [LV.Master]伴坛终老

    发表于 2014-1-21 16:14:06 | 显示全部楼层
    qinkaiabc 发表于 2014-1-17 16:03
    http://fritzing.org/home/

    这个好~~~
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

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



    手机版|小黑屋|与非网

    GMT+8, 2024-5-3 08:51 , Processed in 0.152002 second(s), 25 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.