LCD1602显示

msp430f5529控制LCD1602显示

一、管脚图

LCD1602显示_第1张图片

二、寄存器选择指令

LCD1602显示_第2张图片

三、代码实现

main.c

#include 
#include "LCD1602.h"
unsigned char s3[] = "20";
unsigned char s4[] = "0.01";

unsigned char s1[]="R=";
unsigned char s2[]="C=";
unsigned char s5[]="Ω";
unsigned char s6[]="F";
int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;
    LCD1602_Initi();
    LCD1602_WriteCMD(0x80);//第一行
    DispStr(s1);
    LCD1602_WriteCMD(0x80+0x4);
    DispStr(s5);
    LCD1602_WriteCMD(0x88);//第三行
    DispStr(s2);
    LCD1602_WriteCMD(0x88+0x04);
    DispStr(s6); 
    
    while(1){
    write(s3,s4); 
    }
  while(1);
}

LCD1602.c

#include 
#include 
#include "LCD1602.h"
#define CPU_F ((double)8000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
#define DataDir     P3DIR
#define DataPort    P3OUT
#define Busy        0x80
#define CLR_RS P1OUT&=~BIT3;    //RS = P1.3
#define SET_RS P1OUT|=BIT3;
#define CLR_RW P1OUT&=~BIT4;    //RW = P1.4
#define SET_RW P1OUT|=BIT4;
#define CLR_EN P1OUT&=~BIT5;    //EN = P1.5
#define SET_EN P1OUT|=BIT5; 
void Disp1Char(unsigned char data)
{
    LCD1602_WriteDATA(data);
}
void DispStr(unsigned char *ptr)
{
    unsigned char i,n;
    n = strlen(ptr);
    for (i=0;i0;x--)
      for(int y=120;y>0;y--);
}
void LCD_CLR()
{
    CLR_RS;
    CLR_RW;
    DataPort=0xff;
    SET_EN;
    CLR_EN;
}
void LCD1602_Initi()
{
  
  P3DIR|=0xff;
  P1DIR |= BIT3 + BIT4 + BIT5;
  P3REN = 0XFF;
  P1REN |= BIT3 + BIT4 + BIT5;  
  LCD1602_WriteCMD(0x38);        //功能设定指令,设定数据总线位数、显示行数及字形
  LCD1602_WriteCMD(0x0c);        //显示功能开,无光标,不闪烁。
  LCD1602_WriteCMD(0x06);       //进入模式,每次定入1位数据后光标右移,屏不移动
  LCD1602_WriteCMD(0x01);       //清屏
  delay_ms(10);
//  LCD1602_WriteCMD(0x08);        //显示开关控制指令,显示功能关,无光标
//  LCD1602_WriteCMD(0x01);        //清屏  
//  LCD1602_WriteCMD(0x06);        //进入模式,每次定入1位数据后光标右移,屏不移动
//  LCD1602_WriteCMD(0x14);        //设定显示屏或光标移动方向指令,写入新的数据后,光标右移,显示屏不移动。 
//  LCD1602_WriteCMD(0x0c);        //显示功能开,无光标,不闪烁。
}

LCD1602.h

/*
* LCD1602.h
*
*  Created on: 2018年6月3日
*      Author: Sunnl
*/

#ifndef LCD1602_H_//if not define的简写
#define LCD1602_H_
#include 

void Disp1Char(unsigned char data);
void DispStr(unsigned char *ptr);
void DispNumb(unsigned int *ptr);
void LCD1602_WriteCMD(unsigned char cmd);
void LCD1602_WriteDATA(unsigned char Data);
void LCD1602_Initi();
void Delay_ms(unsigned int t);
unsigned char Busy_Check();
void LCD_CLR();
void write(unsigned char *s3,unsigned char *s4);
#endif
/* LCD1602_H_ */

你可能感兴趣的:(单片机)