DS1302顯示時(shí)間
/**************************************************************************
THE 1602 CHAR LCD LIB
COPYRIGHT (c) 2005 BY JJJ.
-- ALL RIGHTS RESERVED --
File Name: LCD.h
Author: Jiang Jian Jun
Created: 2005/4/3
Modified:NO
Revision: 1.0
***************************************************************************/
#ifndef LCD_CHAR_1602_2005_4_9
#define LCD_CHAR_1602_2005_4_9
#include
//Port Definitions**********************************************************
sbit LcdRs= P2^0;
sbit LcdRw= P2^1;
sbit LcdEn = P2^2;
sfr DBPort = 0x80;//P0=0x80,P1=0x90,P2=0xA0,P3=0xB0.數(shù)據(jù)端口
//內(nèi)部等待函數(shù)**************************************************************************
unsigned char LCD_Wait(void)
{
LcdRs=0;
LcdRw=1;_nop_();
LcdEn=1;_nop_();
//while(DBPort&0x80);//在用Proteus仿真時(shí),注意用屏蔽此語句,在調(diào)用GotoXY()時(shí),會(huì)進(jìn)入死循環(huán),
//可能在寫該控制字時(shí),該模塊沒有返回寫入完備命令,即DBPort&0x80==0x80
//實(shí)際硬件時(shí)打開此語句
LcdEn=0;
return DBPort;
}
//向LCD寫入命令或數(shù)據(jù)************************************************************
#define LCD_COMMAND0 // Command
#define LCD_DATA1 // Data
#define LCD_CLEAR_SCREEN0x01 // 清屏
#define LCD_HOMING 0x02 // 光標(biāo)返回原點(diǎn)
void LCD_Write(bit style, unsigned char input)
{
LcdEn=0;
LcdRs=style;
LcdRw=0;_nop_();
DBPort=input;_nop_();//注意順序
LcdEn=1;_nop_();//注意順序
LcdEn=0;_nop_();
LCD_Wait();
}
//設(shè)置顯示模式************************************************************
#define LCD_SHOW0x04 //顯示開
#define LCD_HIDE0x00 //顯示關(guān)
#define LCD_CURSOR0x02 //顯示光標(biāo)
#define LCD_NO_CURSOR0x00 //無光標(biāo)
#define LCD_FLASH0x01 //光標(biāo)閃動(dòng)
#define LCD_NO_FLASH0x00 //光標(biāo)不閃動(dòng)
void LCD_SetDisplay(unsigned char DisplayMode)
{
LCD_Write(LCD_COMMAND, 0x08|DisplayMode);
}
//設(shè)置輸入模式************************************************************
#define LCD_AC_UP0x02
#define LCD_AC_DOWN0x00 // default
#define LCD_MOVE0x01 // 畫面可平移
#define LCD_NO_MOVE0x00 //default
void LCD_SetInput(unsigned char InputMode)
{
LCD_Write(LCD_COMMAND, 0x04|InputMode);
}
//移動(dòng)光標(biāo)或屏幕************************************************************
/*
#define LCD_CURSOR0x02
#define LCD_SCREEN0x08
#define LCD_LEFT0x00
#define LCD_RIGHT0x04
void LCD_Move(unsigned char object, unsigned char direction)
{
if(object==LCD_CURSOR)
LCD_Write(LCD_COMMAND,0x10|direction);
if(object==LCD_SCREEN)
LCD_Write(LCD_COMMAND,0x18|direction);
}
*/
//初始化LCD************************************************************
void LCD_Initial()
{
LcdEn=0;
LCD_Write(LCD_COMMAND,0x38); //8位數(shù)據(jù)端口,2行顯示,5*7點(diǎn)陣
LCD_Write(LCD_COMMAND,0x38);
LCD_SetDisplay(LCD_SHOW|LCD_NO_CURSOR); //開啟顯示, 無光標(biāo)
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
LCD_SetInput(LCD_AC_UP|LCD_NO_MOVE); //AC遞增, 畫面不動(dòng)
}
//************************************************************************
void GotoXY(unsigned char x, unsigned char y)
{
if(y==0)
LCD_Write(LCD_COMMAND,0x80|x);
if(y==1)
LCD_Write(LCD_COMMAND,0x80|(x-0x40));
}
void Print(unsigned char *str)
{
while(*str!=