當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]**************************************************************************************************LCD12864.H*******************************LCD12864 8線程序p1 8位數(shù)據(jù)端口rs P2.0rw P2.1en P2.2PSB 已經(jīng)外

**************************************************************************************************

LCD12864.H

*******************************
LCD12864 8線程序
p1 8位數(shù)據(jù)端口
rs P2.0
rw P2.1
en P2.2
PSB 已經(jīng)外接高電平
RST 已經(jīng)外接高電平
********************************

#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

************************************************************
函數(shù)定義
************************************************************
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);//因?yàn)樽铋L(zhǎng)的寫(xiě)命令時(shí)間為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!='