您好,欢迎来到微智科技网。
搜索
您的当前位置:首页MSP430g2553的LCD1602显示程序

MSP430g2553的LCD1602显示程序

来源:微智科技网


#include

/*

* main.c

*/

unsigned char tab[]={\"01234567\"};

#define uchar unsigned char

#define uint unsigned int

#define lcd_dir P1DIR //

#define lcd_out P1OUT //

#define RS_1 P2OUT |= BIT0 //RS至

#define RS_0 P2OUT &= ~BIT0 //RS置

#define RW_1 P2OUT |= BIT1 //RW置

#define RW_0 P2OUT &= ~BIT1

#define E_1 P2OUT |= BIT2

#define E_0 P2OUT &= ~BIT2

#define OUT P2DIR |= BIT0 + BIT1 + BIT2//写指令

void WriteInstrustion(uchar dictate)

{

OUT;

lcd_dir = 0xff;

_delay_cycles(5000);

E_0;

RS_0;

// P2.0,1,2输出

RW_0;

_delay_cycles(2);

E_1;

lcd_out = dictate;

_delay_cycles(1000);

E_0;

}

//写地址

void WriteAddress(uchar x)

{

WriteInstrustion(x|0x80);

}

//写数据

void WriteData(uchar y)

{

OUT;

lcd_dir = 0xff;

_delay_cycles(5000);

RS_1;

E_0;

RW_0;

_delay_cycles(2);

E_1;

lcd_out = y;

_delay_cycles(1000);

E_0;

RS_0;

}

//初始化

void Lcd_Init()

{

_delay_cycles(15000);

WriteInstrustion(0x38);

_delay_cycles(50);

WriteInstrustion(0x38);

WriteInstrustion(0x38);

WriteInstrustion(0x0c);

WriteInstrustion(0x06);

WriteInstrustion(0x01); //清屏幕指令,将以前的显示内容清除

}

//AD初始化程序:

//入口参数:无

//出口参数:无

}

//主函数

void main(void)

{

uint t=0;

WDTCTL=WDTPW+WDTHOLD;

Lcd_Init();

ADC10_Init();

WriteAddress(0x03);

WriteData('V');

WriteData('P');

WriteData('P');

WriteData(':');

while(1);

{

//

}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 7swz.com 版权所有 赣ICP备2024042798号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务