×
嵌入式 > 技术百科 > 详情

12864_8线库程序

发布时间:2020-06-20 发布时间:
|

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

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,只能仿真汉字,不能仿真字符和数字,否则显示的不清晰,一团乱码。

  


『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
NTMD6N03R2G的技术参数