当前位置:首页 > 单片机 > 单片机
[导读]**************************************************************************************************LCD12864.H*******************************LCD12864 8线程序p1 8位数据端口rs P2.0rw P2.1en P2.2PSB 已经外

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

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


本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

12864液晶的驱动和1602的类似,只不过是多了几个扩展的功能,不如画图功能

关键字: 12864 单片机

Ds3231+12864液晶显示AT89C51带温度功能的时钟程序。

关键字: 12864 at89c51 ds3231 时钟程序 液晶显示

void curve(unsigned char xlable,unsigned char ylable,bit dot){unsigned char H[1]={0};//读RAM寄存unsigned char L[1...

关键字: 12864 51单片机 打点程序

;模 块 名:ST7920 控制器 NS12864R;功能描述:库内汉字的显示;***************************; ; NS12864显示程序(库内汉字) ; ;****************...

关键字: 12864 LCD 显示

// HS12864-15B - 并行方式 - 显示汉字 - 图形// 带字库 // 芯片 ATMEGA16L // 时钟 4MHz 内部 // 功能1:汉字及字母的显示,汉字不能错位 // 功能2:图形显示,显...

关键字: 12864 带字库 并行显示

超声波测距的模块,51单片机接上12864液晶,HC-SR04超声波模块,就可以了,具体程序没怎么看,超声波模块的硬件也不晓得,今天先贴个图,贴个程序吧(程序是淘宝买的模块附赠的)。超声波测距51单片机12864液晶显示...

关键字: 12864 51单片机 液晶显示 超声波测距

#include "pic.h" #define RS RC0 #define RW RC1 #define E RC2 #define PSB RC3 #define RST RC4 /...

关键字: 12864 LCD 图形显示

// HS12864-15B程序 图形显示和汉字显示// st7920控制器#include #include #include #define lcd_bus P0 // 数据总线 sbit rs =P2...

关键字: 12864 带字库 汉字 显示图形

12864液晶显示程序#include #include sbit RS = P2^5;sbit RW = P2^6;sbit E = P2^7;sbit RES = P3^5;#define Lcd_Bus P0 //...

关键字: 12864 液晶显示

/*12864中文字库测试程*/#include #include #include #include unsigned char code IC_DAT[];unsigned char code pic1[];unsi...

关键字: 12864 中文字库 串口测试
关闭
关闭