標(biāo)題:
LCD1602.h頭文件下載<可導(dǎo)入CGRAM>
[打印本頁]
作者:
liuqq
時間:
2015-5-19 01:49
標(biāo)題:
LCD1602.h頭文件下載<可導(dǎo)入CGRAM>
LCD1602.h液晶驅(qū)動頭文件下載:
#ifndef _LCD1602_H_
#define _LCD1602_H_
#include <reg51.h>
//#include <STC12C5A60S2.h>
#define uint8 unsigned char
#define uint16 unsigned int
//////////////////////////////////////////////////////////
#define IODATA P0
sbit E =P2^2; //1602使能引腳
sbit RW =P2^1; //1602讀寫引腳
sbit RS =P2^0; //1602數(shù)據(jù)/命令選擇引腳
//////////////////////////////////////////////////////////
void delay1602()
{
uint8 i=10;
while(i--);
}
void del1602(uint16 delay)
{
uint16 i,j;
for(i=0;i<delay;i++)
for(j=0;j<=148;j++);
}
/********************************************************************
* 名稱 : bit Busy(void)
* 功能 : 讀狀態(tài)函數(shù),是否處在忙狀態(tài)
***********************************************************************/
void Busy(void)
{
bit busy_flag = 1;
IODATA = 0xff;
RS = 0;
delay1602();
RW = 1;
delay1602();
E = 1;
while(1)
{
busy_flag = (bit)(IODATA & 0x80);
if(busy_flag == 0)
{
break;
}
}
E = 0;
}
/********************************************************************
* 名稱 : lcd1602_wcmd(uint8 tdata)
* 功能 : 1602命令函數(shù)
* 輸入 : 輸入的命令值
***********************************************************************/
void lcd1602_wcmd(uint8 tdata)
{
RS = 0;
delay1602();
RW = 0;
delay1602();
E = 0;
delay1602();
IODATA = tdata;
delay1602();
E = 1;
delay1602();
E = 0;
}
/********************************************************************
* 名稱 : lcd1602_wdata(uint8 tdata)
* 功能 : 1602寫數(shù)據(jù)函數(shù)
* 輸入 : 需要寫入1602的數(shù)據(jù)
***********************************************************************/
void lcd1602_wdata(uint8 tdata)
{
Busy();
delay1602();
RS = 1;
delay1602();
RW = 0;
delay1602();
E = 0;
delay1602();
IODATA = tdata;
delay1602();
E = 1;
delay1602();
E = 0;
}
/********************************************************************
* 名稱 : lcd1602_init()
* 功能 : 1602初始化
***********************************************************************/
void lcd1602_init(void)
{
del1602(15);
lcd1602_wcmd(0x38);
del1602(5);
lcd1602_wcmd(0x38);
del1602(5);
lcd1602_wcmd(0x38);
lcd1602_wcmd(0x38);
Busy();
lcd1602_wcmd(0x08);
Busy();
lcd1602_wcmd(0x01);
Busy();
lcd1602_wcmd(0x06);
Busy();
lcd1602_wcmd(0x0c);
}
/********************************************************************
* 名稱 : lcd1602_char(uint8 hang,uint8 lie,char sign)
* 功能 : lcd1602_char(1,5,'A')
* 輸入 : 行,列,需要輸入1602的數(shù)據(jù)
***********************************************************************/
void lcd1602_char(uint8 hang,uint8 lie,char sign)
{
uint8 a;
if(hang == 1)
{
a = 0x80;
}
if(hang == 2)
{
a = 0xc0;
}
a = a + lie - 1;
Busy();
lcd1602_wcmd(a);
Busy();
lcd1602_wdata(sign);
}
/********************************************************************
* 名稱 : lcd1602_string(uint8 hang,uint8 lie,uint8 *p)
* 功能 : lcd1602_string(1,5,"happy!")
* 輸入 : 行,列,需要輸入1602的數(shù)據(jù)
***********************************************************************/
void lcd1602_string(uint8 hang,uint8 lie,uint8 *p)
{
uint8 a;
if(hang == 1)
{
a = 0x80;
}
if(hang == 2)
{
a = 0xc0;
}
a = a + lie - 1;
while(1)
{
Busy();
lcd1602_wcmd(a);
Busy();
lcd1602_wdata(*p);
a++;
p++;
if((*p == '\0')||(a==0x90)||(a==0xd0))
{
break;
}
}
}
/********************************************************************
* 名稱 : lcd1602_write_pic(uint8 add,uint8 *pic_num)
* 功能 : lcd1602_string(i,pic[i])
* 輸入 : 寫入自定義字符到CGRAM
***********************************************************************/
void lcd1602_write_pic(uint8 add,uint8 *pic_num)
{
uint8 i;
add=add<<3;
for(i=0;i<8;i++)
{
lcd1602_wcmd(0x40|add+i);
lcd1602_wdata(*pic_num++);
}
}
/********************************************************************
* 名稱 : lcd1602_wdata10(uint8 add,uint16 date);
* 功能 : lcd1602_wdata10(0x80,5000)
* 輸入 : 寫十進(jìn)制到地址
***********************************************************************/
void lcd1602_wdata10(uint8 add,uint16 date)
{
uint8 L1,L2,L3,L4,L5,a;
L5=date/10000;
L4=date%10000/1000;
L3=date%10000%1000/100;
L2=date%10000%1000%100/10;
L1=date%10000%1000%100%10;
if(L1!=0){a=1;};
if(L2!=0){a=2;};
if(L3!=0){a=3;};
if(L4!=0){a=4;};
if(L5!=0){a=5;};
switch (a){
case 5:
lcd1602_wcmd(add);
lcd1602_wdata(0x30+L5);
lcd1602_wdata(0x30+L4);
lcd1602_wdata(0x30+L3);
lcd1602_wdata(0x30+L2);
lcd1602_wdata(0x30+L1);break;
case 4:
lcd1602_wcmd(add);
lcd1602_wdata(0x30+L4);
lcd1602_wdata(0x30+L3);
lcd1602_wdata(0x30+L2);
lcd1602_wdata(0x30+L1);break;
case 3:
lcd1602_wcmd(add);
lcd1602_wdata(0x30+L3);
lcd1602_wdata(0x30+L2);
lcd1602_wdata(0x30+L1);break;
case 2:
lcd1602_wcmd(add);
lcd1602_wdata(0x30+L2);
lcd1602_wdata(0x30+L1);break;
case 1:
lcd1602_wcmd(add);
lcd1602_wdata(0x30+L1);break;
default:break;
}
}
/********************************************************************
* 名稱 : lcd1602_wdata16(uint16 date);
* 功能 : lcd1602_wdata16(0x10)
* 輸入 : 寫十六進(jìn)制到地址
***********************************************************************/
void lcd1602_wdata16(uint16 date)
{
uint8 dat_H,dat_L;
dat_H=date>>8;
dat_L=date;
lcd1602_wdata(dat_H);
lcd1602_wdata(dat_L);
}
#endif
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1