1602的RS接P2.0,RW接P2.1,E接P2.2
7~14的8个引脚接MSP430的P1.0~P1.7,其余按照1602引脚要求连接即可。
#include<msp430g2553.h>
#define uchar unsigned char
#define uint unsigned int
#define P20 0
#define P21 1
#define P22 2
#define RS_CLR P2OUT &= ~(1 << P20) //RS置低
#define RS_SET P2OUT |= (1 << P20) //RS置高
#define RW_CLR P2OUT &= ~(1 << P21) //RW置低
#define RW_SET P2OUT |= (1 << P21) //RW置高
#define EN_CLR P2OUT &= ~(1 << P22) //E置低
#define EN_SET P2OUT |= (1 << P22) //E置高
uchar num;
int ADC_CHO;
int c;
int data;
unsigned char x;
unsigned char y;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com) //输入数据
{
RS_CLR; //RS置低 输入指令
P1OUT=com;
delay(5);
EN_SET;
delay(5);
EN_CLR; //E置低 1->0 执行指令
}
void write_data(uchar data) //输出数据
{
RS_SET; //RS置高 RS=1输出数据
P1OUT=data;
delay(5);
EN_SET;
delay(5);
EN_CLR; //E置低 1->0 执行指令
}
void init() //1602初始化,请参考1602的资料
{
EN_CLR;
write_com(0x38); //设置16*2显示,5*7点阵,8位数据接口
write_com(0x0e); //光标不显示
write_com(0x06); //写入新数据后光标右移,显示频不移动
write_com(0x01); //0000000001 清屏
write_com(0x80); //修改指针的位置
}
1