?? lcd1602_.h
字號:
/*********************************************************************
微 雪 電 子 WaveShare http://www.waveShare.net
目 的: 建立LCD1602的4位數(shù)據(jù)模式操作庫
目標(biāo)系統(tǒng): 基于AVR單片機(jī)
應(yīng)用軟件: ICCAVR
版 本: Version 1.0
圓版時間: 2004-08-25
開發(fā)人員: SEE
說 明: 若用于商業(yè)用途,請保留此段文字或注明代碼來源
深 圳 市 微 雪 電 子 有 限 公 司 保 留 所 有 的 版 權(quán)
*********************************************************************/
/*01010101010101010101010101010101010101010101010101010101010101010101
----------------------------------------------------------------------
版本更新記錄:
版 本: Version 1.1
圓版時間: 2005-03-25
----------------------------------------------------------------------
入口參數(shù)說明:
// control port
//#define SET_RS sbi(PORTB,5)
//#define CLR_RS cbi(PORTB,5)
//#define OUT_RS sbi(DDRB,5)
//#define CLR_RW cbi(PORTB,6)
//#define OUT_RW sbi(DDRB,6)
//#define SET_E sbi(PORTB,7)
//#define CLR_E cbi(PORTB,7)
//#define OUT_E sbi(DDRB,7)
// data port
//#define SET_D4 sbi(PORTD,4)
//#define CLR_D4 cbi(PORTD,4)
//#define OUT_D4 sbi(DDRD,4)
//#define SET_D5 sbi(PORTD,5)
//#define CLR_D5 cbi(PORTD,5)
//#define OUT_D5 sbi(DDRD,5)
//#define SET_D6 sbi(PORTD,6)
//#define CLR_D6 cbi(PORTD,6)
//#define OUT_D6 sbi(DDRD,6)
//#define SET_D7 sbi(PORTD,7)
//#define CLR_D7 cbi(PORTD,7)
//#define OUT_D7 sbi(DDRD,7)
// busy port
//#define GET_BF gbi(PIND,7)
//#define OUT_BF sbi(DDRD,7)
//#define IN_BF cbi(DDRD,7)
----------------------------------------------------------------------
接口定義:
LCD1602 ATmega16
1.GND -------- GND
2.VCC -------- VCC
3.V0 -------- V0
4.RS -------- 由外部程序定義
5.R/W -------- 由外部程序定義
6.E -------- 由外部程序定義
7.D0 -------- NC
8.D1 -------- NC
9.D2 -------- NC
10.D3 -------- NC
11.D4 -------- 由外部程序定義
12.D5 -------- 由外部程序定義
13.D6 -------- 由外部程序定義
14.D7 -------- 由外部程序定義
15.LED+ -------- VCC
16.LED- -------- GND
說明:
(1)使用ATmega16的7根IO口操作LCD1602
(2)該程序的優(yōu)點是:7根IO可任意定義,不需分布在固定的一組PORT口上
(3)該程序的缺點是:IO定義的寫法較為繁瑣
----------------------------------------------------------------------
待定參數(shù)說明:
//#define DELAY() {_nop_();_nop_();_nop_();}
----------------------------------------------------------------------
對外變量說明:
----------------------------------------------------------------------
對外函數(shù)說明:
----------------------------------------------------------------------
10101010101010101010101010101010101010101010101010101010101010101010*/
#ifndef LCD1602_H
#define LCD1602_H
#include "D:\ICC_H\CmmICC.H"
/* 待定參數(shù) */
#define DELAY() {NOP();NOP();NOP();NOP();NOP();NOP();NOP();NOP();}
/* 不考慮移植性的寫法 */
//uint8 bdata bdat;
//sbit bdat0=bdat^0;
//sbit bdat1=bdat^1;
//sbit bdat2=bdat^2;
//sbit bdat3=bdat^3;
//sbit bdat4=bdat^4;
//sbit bdat5=bdat^5;
//sbit bdat6=bdat^6;
//sbit bdat7=bdat^7;
/* 考慮移植性的寫法 */
uint8 bdat;
#define bdat0 (bdat&0x01)
#define bdat1 (bdat&0x02)
#define bdat2 (bdat&0x04)
#define bdat3 (bdat&0x08)
#define bdat4 (bdat&0x10)
#define bdat5 (bdat&0x20)
#define bdat6 (bdat&0x40)
#define bdat7 (bdat&0x80)
#define CGRAM0 0x00
#define CGRAM1 0x01
#define CGRAM2 0x02
#define CGRAM3 0x03
#define CGRAM4 0x04
#define CGRAM5 0x05
#define CGRAM6 0x06
#define CGRAM7 0x07
#define TRUE 1
#define FALSE 0
bool LCD1602Err = FALSE;
/*--------------------------------------------------------------------
函數(shù)名稱:LCD1602讀讀讀讀讀忙~
函數(shù)功能:都說是讀讀讀讀讀忙咯~
注意事項:對于高速CPU,應(yīng)加延時,好像是廢話~
提示說明:無
輸 入:
返 回:無
--------------------------------------------------------------------*/
void busy(void)
{
uint16 busyCounter=0;
bool busySta; //用于探測 lcd busy status
IN_BF;
SET_D4;
SET_D5;
SET_D6;
SET_D7;
DELAY();
CLR_RS;
DELAY();
SET_RW;
DELAY();
do
{
SET_E;
DELAY();
/* 這里讀取AC4-AC6位及BF的值,程序不需記錄AC4-AC6的值,所以不存儲 */
busySta=(bool)GET_BF;
CLR_E;
DELAY();
/* 讀取 "BUSY"時,"D4-D7"狀態(tài)可能已經(jīng)改變,必須再次設(shè)為輸出"1" */
SET_D4;
SET_D5;
SET_D6;
SET_D7;
DELAY();
SET_E;
DELAY();
/* 這里讀取AC0-AC3位的值,程序不需記錄AC0-AC3的值,所以不存儲 */
CLR_E;
DELAY();
if(busyCounter==1000)
{
LCD1602Err=TRUE; //標(biāo)識LCD1602錯誤,方便上繳系統(tǒng)報錯
return ; //避免由于LCD1602錯誤而導(dǎo)致程序阻塞
}
busyCounter++;
}
while(busySta);
LCD1602Err=FALSE;
CLR_E;
OUT_BF;
}
/*--------------------------------------------------------------------
函數(shù)名稱:LCD1602寫操作
函數(shù)功能:
注意事項:對于高速CPU,應(yīng)加延時,好像是廢話~
提示說明:無
輸 入:
返 回:無
--------------------------------------------------------------------*/
void write(bool flag,uint8 dat) //flag=0:command,flag=1:data
{
bdat=dat;
busy();
if(flag)
SET_RS;
else
CLR_RS;
DELAY();
CLR_RW;
DELAY();
if(bdat4)
SET_D4;
else
CLR_D4;
if(bdat5)
SET_D5;
else
CLR_D5;
if(bdat6)
SET_D6;
else
CLR_D6;
if(bdat7)
SET_D7;
else
CLR_D7;
DELAY();
SET_E;
DELAY();
CLR_E;
DELAY();
if(bdat0)
SET_D4;
else
CLR_D4;
if(bdat1)
SET_D5;
else
CLR_D5;
if(bdat2)
SET_D6;
else
CLR_D6;
if(bdat3)
SET_D7;
else
CLR_D7;
DELAY();
SET_E;
DELAY();
CLR_E;
DELAY();
}
/*--------------------------------------------------------------------
函數(shù)名稱:LCD1602讀操作
函數(shù)功能:
注意事項:對于高速CPU,應(yīng)加延時,好像是廢話~
提示說明:無
輸 入:
返 回:無
--------------------------------------------------------------------*/
//void read(uint8 adr)
//{
//}
/*--------------------------------------------------------------------
函數(shù)名稱:LCD1602設(shè)置CGRAM內(nèi)容
函數(shù)功能:
注意事項:對于高速CPU,應(yīng)加延時,好像是廢話~
提示說明:調(diào)用LCD1602_setCG(0,userCh),則寫入用戶定義的字符"userCh"
輸 入:"adr"數(shù)據(jù)范圍:0-8,"buf"為用戶需要寫入的字符"userCh"
返 回:無
--------------------------------------------------------------------*/
void LCD1602_setCGRAM(uint8 adr,const uint8 buf[8])
{
uint8 i;
write(0,0x40+adr*8);
for(i=0;i<8;i++)
write(1,buf[i]);
/* 不得采樣下面寫法,因為傳入的是數(shù)組,最后一個不是'\0' */
//while(*buf)
//write(1,*buf++);
}
/*--------------------------------------------------------------------
函數(shù)名稱:LCD1602命令設(shè)置
函數(shù)功能:
注意事項:對于高速CPU,應(yīng)加延時,好像是廢話~
提示說明:
輸 入:"CLR_SCR"/"GO_HOME"/"AC_INC"/"AC_DEC"...
返 回:無
--------------------------------------------------------------------*/
//---- function ------ 1 -------- 0 ----LcdWordPos--
// dispEn | Enable | Disable | bit2
// cursorEn | Enable | Disable | bit1
// blinkEn | Enable | Disable | bit0
//------------------------------------------------------
// isACinc | INC_AC | DEC_AC | bit1
// shiftEn | Enable | Disable | bit0
//------------------------------------------------------
void LCD1602_setCmd(uint8 *str)
{
static bool dispEn =0;
static bool cursorEn=0;
static bool blinkEn =0;
static bool shiftEn =0;
static bool isACinc =0;
if(!strcmp(str,"CLR_SCR")) //clear screen
write(0,0x01);
else if(!strcmp(str,"GO_HOME")) //set AC go home
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -