12864_8线库程序
扫描二维码
随时随地手机看文章
**************************************************************************************************
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!='