**************************************************************************************************
lcd12864.h
*******************************
lcd12864
8线程序
p1 8位数据端口
rs
p2.0
rw p2.1
en
p2.2
psb 已经外接高电平
rst
已经外接高电平
********************************
#ifndef __lcd12864_h__
#define __lcd12864_h__
#include"msp430f2232.h"
*******************************
引脚定义
*******************************
#define rs_0 p2out &=
~bit0
#define rs_1 p2out |= bit0
#define rw_0 p2out &=
~bit1
#define rw_1 p2out |= bit1
#define en_0 p2out &=
~bit2
#define en_1 p2out |= bit2
******************************
命令字符定义
******************************
#define first_line 0x80
#define
second_line 0x90
#define third_line 0x88
#define fourth_line 0x98
************************************************************
函数定义
************************************************************
extern
void lcd12864_port_init(void);
extern void
lcd12864_wait_for_enable(void);
extern void lcd12864_write_command(unsigned
int com);
extern void lcd12864_write_data(unsigned int dat);
extern void
lcd12864_init(void);
extern void lcd12864_write_string(char adress,char *str);
#endif
**************************************************************************************************
lcd12864.c
#include"lcd12864.h"
void lcd12864_port_init(void)
{
p2dir=bit0 bit1 bit2;
p1dir=0xff;
}
void lcd12864_wait_for_enable(void)
{
char busy;
rs_0;
rw_1;
do
{
p1dir=0x00;
en_1;
busy =
p1in;
en_0;
}
while(busy &
0x80);
p1dir = 0xff;
}
void lcd12864_write_command(unsigned int com)
{
lcd12864_wait_for_enable();
rs_0;
rw_0;
p1out =
com;
en_1;
__delay_cycles(5000);//因为最长的写命令时间为4.7ms
en_0;
}
void lcd12864_write_data(unsigned int dat)
{
lcd12864_wait_for_enable();
rs_1;
rw_0;
p1out =
dat;
en_1;
__delay_cycles(500);
en_0;
}
void lcd12864_init(void)
{
__delay_cycles(500000);
lcd12864_write_command(0x30);
lcd12864_write_command(0x01);
lcd12864_write_command(0x06);
lcd12864_write_command(0x0c);
}
void lcd12864_write_string(char adress,char *str)
{
lcd12864_write_command(adress);
while(*str!='\0')
{
lcd12864_write_data(*str);
str ;
}
}
**************************************************************************************************
主函数
#include
"lcd12864.h"
int main( void )
{
// stop watchdog timer to
prevent time out reset
wdtctl = wdtpw wdthold;
lcd12864_port_init();
lcd12864_init();
lcd12864_write_string(0x80,"李白斗酒诗百篇");
lcd12864_write_string(0x90,"长安市上酒家眠");
lcd12864_write_string(0x88,"天子呼来不上船");
lcd12864_write_string(0x98,"自称臣是酒中仙");
while(1);
}
**************************************************************************************************
仿真效果图,在proteus中,用12864,只能仿真汉字,不能仿真字符和数字,否则显示的不清晰,一团乱码。
『本文转载自网络,九游会j9的版权归原作者所有,如有侵权请联系删除』