(Display)LCD1602程序__版本2
LCD1602從我接觸單片機(jī)開(kāi)始就在用,以前用的時(shí)候,有時(shí)用RS和EN,RW接地,有時(shí)也用四線模式,但是用到最后,我發(fā)現(xiàn)還是用8跟數(shù)據(jù)線,RS,RW,EN都接到單片機(jī)上是最好用的......
Proteus仿真圖:
LCD1602.H代碼:
#define _LCD1602_H_
#include
#include "TYPEDEF.H"
//液晶初始化函數(shù):
void LCD1602_Init();
//液晶設(shè)置顯示位置函數(shù)/設(shè)置DDRAM位置
void LCD1602_SetPosition( uint8 x, uint8 y );
//液晶寫(xiě)緩存函數(shù)
void LCD1602_WriteBuffer( uint8 *buffer );
//液晶寫(xiě)字符串函數(shù)
void LCD1602_WriteString( uint8 x, uint8 y, uint8 *str );
//顯示數(shù)值函數(shù)
void LCD1602_WriteNum( uint8 x, uint8 y, uint32 dat );
//顯示溫度函數(shù)
void LCD1602_DispTemp( uint8 x, uint8 y, int8 temp );
//顯示兩位數(shù)函數(shù)
void LCD1602_Disp2bit( uint8 x, uint8 y, uint8 dat );
//開(kāi)啟光標(biāo)函數(shù)
void LCD1602_OpenCursor( void );
//關(guān)閉光標(biāo)函數(shù)
void LCD1602_CloseCursor( void );
//設(shè)定光標(biāo)位置函數(shù)
void LCD1602_SetCursor( uint8 x, uint8 y );
#endif
LCD1602.C代碼:
#include "LCD1602.H"
#include "TYPEDEF.H"
#include "CONFIG.H"
//寫(xiě)命令函數(shù)
static void LCD1602_WriteCommand( uint8 com );
//判忙函數(shù)
static void LCD1602_CheckBusy();
//寫(xiě)數(shù)據(jù)函數(shù)
static void LCD1602_WriteData( uint8 dat );
//將數(shù)據(jù)轉(zhuǎn)化為字符串
static void Uint32_To_String( uint8 *str, uint32 dat );
//液晶初始化函數(shù)
void LCD1602_Init()
{
LCD1602_WriteCommand( 0x38 );//8跟數(shù)據(jù)線,2行顯示,5*8點(diǎn)陣
LCD1602_WriteCommand( 0x06 );//寫(xiě)入數(shù)據(jù)后光標(biāo)自動(dòng)右移
LCD1602_WriteCommand( 0x01 );//清除DDRAM,清屏
LCD1602_WriteCommand( 0x0c );//不顯示光標(biāo),不閃爍
}
void LCD1602_SetPosition( uint8 x, uint8 y )
{
if( x==0 )
LCD1602_WriteCommand( 0X80+y );
else if( x==1 )
LCD1602_WriteCommand( 0X80+0x40+y );
else
{
char Buffer[]={"Pos Error"};
LCD1602_WriteBuffer( Buffer );
while(1);
}
}
//液晶寫(xiě)緩存函數(shù)
void LCD1602_WriteBuffer( uint8 *buffer )
{
while( *buffer != '