#include
typedef unsigned char uchar;
typedef unsigned int uint;
//typedef也是一种宏界说类型,其书写方法和#define相反
/*******液晶端口初始化*******/
#define out P3DIR|=BIT0+BIT1+BIT2//把P3_012三个口设为输出
#define lcd_enset P3OUT|=BIT2
#define lcd_enclear P3OUT&=~BIT2
#define lcd_rw1 P3OUT|=BIT1
#define lcd_rw0 P3OUT&=~BIT1
#define lcd_rs1 P3OUT|=BIT0
#definelcd_rs0 P3OUT&=~BIT0
#define keyin (P1IN & 0x0f)
uchar temp,keynum=0;
int shi=23,fen=59,miao=55;//此处用char型会在按键调整减数到0时犯错
/**********/
/*延时子程序*/
//调用8个时钟周期,回来6个,循环4个
//总周期个数为: 8+6+4*n=14+4*n 个时钟周期
//默许800k时钟,所以周期为1.25us 公式批改:17.5+5*n=守时时刻
void delay(unsigned int x)//延时
{
unsigned int i;
i=x;
for(;i>0;i–) ;
}
/******LCD写指令程序***********/
void write_com(unsigned char com)
{ out;
P4DIR=0XFF;
P4OUT=com;
lcd_rw0;
lcd_rs0;
_NOP();
lcd_enclear;
delay(10);
lcd_enset;
delay(10);
lcd_enclear;
}
/***********LCD写数据**************/
void write_data(unsigned char dat)
{ out;
P4DIR=0XFF;
P4OUT=dat;
lcd_rw0;
lcd_rs1;
_NOP();
_NOP();
lcd_enclear;
delay(10);
lcd_enset;
delay(10);
lcd_enclear;
}
/*****写时分秒********/
void write_sfm(uchar add,uchar dat)
{
uchar a,b;
a=dat/10;
b=dat%10;
write_com(0x80+0x40+add);
write_data(a+0x30);
write_data(b+0x30);
}
/*********lcd初始化,写lcd功能与方法操控********/
voidlcd_init()
{ out;
write_com(0x38);
delay(20);
write_com(0x0f);
delay(20);
write_com(0x06);
delay(20);
write_com(0x0c);
delay(20);
write_com(0x01);
delay(20);