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!='')
{
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_8线库程序】
推荐阅读
- 12864LCD的显示
- 用AVR单片机8位数据产生随机数
- LM3S1138入门6,系统时钟设置
- PIC单片机AD转换LED显示程序
- LCD1602 C程序
- IIC的PCF8563实用时钟程序_iccavr
- M50462AP摇控器-PIC解码程序_已测试OK
- keil c51的内部RAM_idata动态内存管理程序
- STM32中VDDA为什么也要接电源才能烧录程序?
- IO口模拟SPI通信C51程序