#ifndef __LCD1602_H__ #define __LCD1602_H__ #include "msp430x14x.h" #define lcden_out P3DIR|=BIT2 #define lcden_in P3DIR&=~BIT2 #define lcden_h P3OUT|=BIT2 #define lcden_l P3OUT&=~BIT2
#define rw_out P3DIR|=BIT1 #define rw_in P3DIR&=~BIT1 #define rw_h P3OUT|=BIT1 #define rw_l P3OUT&=~BIT1
#define rs_out P3DIR|=BIT0 #define rs_in P3DIR&=~BIT0 #define rs_h P3OUT|=BIT0 #define rs_l P3OUT&=~BIT0
#define data P4OUT //写指令 void write_com(uchar com) { lcden_out; rs_out; rw_out; P4DIR=0XFF; rs_l; rw_l; lcden_l; data=com; delay(1); lcden_h; delay(1); lcden_l; } //写数据 void write_date(uchar date) { lcden_out; rs_out; P4DIR=0XFF; rs_h; rw_l; lcden_l; data=date; delay(1); lcden_h; delay(1); lcden_l; } //显示字符串,com为0x80的时候显示第一行,知道end,end小于等于16,因为只有16列,0xc0的时候显示第二行,end同理 void display_string(uchar *p,uchar com,uchar end) { uchar i; write_com(com); for(i=0;i<end;i++) { write_date(p); } } //初始化液晶 void init_lcd() { lcden_out; lcden_l; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); display_string(" hello world! ",0xc0,16); } #endif
|