?? lcd_chinese.h
字號:
/************************************
*程序名:lcd_chinese.h
*功 能:清達液晶HG128642C-LY(帶中文液晶字庫)
動程序帶字符串顯示等基本函數(shù)
*
*作 者: 董志峰
*單 位:湖南理工物電系創(chuàng)新基地
* All rights reseverd
*
*開始時間:2006.11.16
*結(jié)束時間:2006.11.20
*版本信息:
*
*注 備:
*************************************/
#ifndef _LCD_CHINESE_
#define _LCD_CHINESE_
#include <reg52.h>
#include <intrins.h>
#include "delay.h"
#define NULL ((void *) 0)
#define DATABUS P2
sbit RS = P1^0;
sbit RW = P1^1;
sbit E = P1^2;
sbit RST = P0^4;
//sbit speaker = P2^1;
void Delay1us(unsigned char);
void Delay1ms(unsigned int);
void Delay1s(unsigned int);
#ifndef _UNCHAR_
#define _UNCHAR_
typedef unsigned char unchar;
#endif
#ifndef _UNINT_
#define _UNINT_
typedef unsigned int unint;
#endif
/************************************
*函數(shù)名:void lcd_writbyte(char data,bit type)
*功 能:向lcd寫入一字節(jié)
*輸 入:
data:要寫入的數(shù)據(jù)
type:選擇方式(1為數(shù)據(jù)方式,0為命令方式)
*返 回:void
*************************************/
void lcd_writebyte(char dt,bit type)
{
unsigned char busy;
unsigned int wait = 0;
RS = 0;
RW = 1;
do
{
E = 1;
busy = DATABUS;
E = 0;
if(wait++ > 2500)
break;
}while(busy&0x80); //如果忙,一直等待
if(type)
{
RS = 1; //寫數(shù)據(jù)
RW = 0;
}
else
{
RS = 0; //寫指令
RW = 0;
}
DATABUS = dt;
E = 1;
E = 0;
}
#if 0
/************************************
*函數(shù)名:char lcd_read(void)
*功 能:讀取lcd
*輸 入:void
*返 回:char
*************************************/
/*
char lcd_read(void)
{
unsigned char dt;
RS = 1;
RW = 1;
dt = DATABUS;
E = 1;
E = 0;
RW = 1;
return dt;
}*/
#endif
/************************************
*函數(shù)名:void lcd_init(void)
*功 能:初始化lcd
*輸 入:void
*返 回:void
*************************************/
void lcd_init(void)
{
Delay1ms(100);
lcd_writebyte(0x30,0);//設(shè)定基本指令集
Delay1us(100);
lcd_writebyte(0x30,0);//設(shè)定基本指令集
Delay1us(40);
lcd_writebyte(0x0c,0);//顯示開
Delay1us(100);
lcd_writebyte(0x01,0);//清除
Delay1ms(20);
lcd_writebyte(0x06,0);//設(shè)定AC+1
Delay1us(100);
lcd_writebyte(0x80,0);//設(shè)定起始地址
Delay1us(100);
}
/************************************
*函數(shù)名:void lcd_CN(unsigned char x,unsigned char y,char *)
*功 能:顯示漢字
*輸 入:char *,unsigned char x,unsigned char y
漢字:x范圍 0~7 y范圍 0~3
英文:x范圍 0~15 y范圍 0~7
*返 回:void
*************************************/
void lcd_CN(unsigned char *buf,unsigned char x,unsigned char y)
{
unsigned char adr;
adr = (0x80+x);
switch(y)
{
case 2:
adr = adr+16;break;
case 3:
adr = adr+8;break;
case 4:
adr = adr+24;break;
default:
break;
}
lcd_writebyte(adr,0); //設(shè)定DDRAM位址到位址計數(shù)器
Delay1us(100);
while((*buf)!='\0')
{
lcd_writebyte(*(buf++),1);
Delay1us(100);
}
}
#if 0
/************************************
*函數(shù)名:void lcd_CN2(unsigned char (*buf)[],unsigned char x,unsigned char y)
*功 能:顯示漢字
*輸 入:char *,unsigned char x,unsigned char y
漢字:x范圍 0~7 y范圍 0~3
英文:x范圍 0~15 y范圍 0~7
*返 回:void
*注 備:用于2維字符數(shù)組
*************************************/
/*
void lcd_CN2(unsigned char (*buf)[],unsigned char x,unsigned char y)//看清聲明形式!!!
{
unsigned char adr;
unchar i=0;
adr = (0x80+x);
switch(y)
{
case 2:
adr = adr+16;break;
case 3:
adr = adr+8;break;
case 4:
adr = adr+24;break;
default:
break;
}
lcd_writebyte(adr,0); //設(shè)定DDRAM位址到位址計數(shù)器
Delay1us(100);
while(*(*buf+i)!='\0')
{
lcd_writebyte(*(*buf+i),1);
i++;
Delay1us(100);
}
}
unsigned char *d = {"董dzf 志"};
unsigned char *z = {"zf"};
unsigned char *f = {"f"};
main()
{
void (*p)() = &lcd_CN;
lcd_init();
lcd_CN(d,1,1);
lcd_CN(z,2,2);
lcd_CN(f,3,3);
for(;;);
} */
#endif
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -