# include
# define uchar unsigned char
# define uint unsigned int
Sbit LCDRS=P0 ^ 0;
Sbit lcden=P0 ^ 2;
Sbit sh=P0 ^ 0;//595
Sbit ds=P0 ^ 1;
Sbit st=P0 ^ 2;
Sbit RST=P0 ^ 3;//1302
Sbit SCK=P0 ^ 4;
Sbit IO=P0 ^ 5;
//DS1302 address definition
# define ds1302_sec_add 0 x80//SEC data address
# define ds1302_min_add 0 x82//score according to address
# define ds1302_hr_add 0 x84//data address
# define ds1302_date_add 0 x86//day data address
# define ds1302_month_add 0 x88//data address
# define ds1302_day_add data address 0 x8a//week
# define ds1302_year_add 0 x8c//year data address
# define ds1302_control_add 0 x8e//control data address
# define ds1302_charger_add 0 x90
# define ds1302_clkburst_add 0 xbe
Uchar dis_time_buf [16]={0};
//initial time definition
Uchar time_buf [8]={x06 0 x20, 0 x10, 0, 0 x01, 0 x23, 0 x59, 0 x55, 0 x02};//initial time on June 1, 2010, 23 points and 59 minutes and 55 seconds Tuesday
//function: delay 1 millisecond
//entrance parameters: x
//export parameters: no
//description: when crystals to 12 m, j<112; When the crystals is 11.0592 M, j<122
Void Delay_xms (uint x)
{
Uint I, j;
for(i=0; I
}
//function: 12 us delay
//microcontroller STC89C52 to 1 t, that is, a clock/machine cycle, at 12 times the rate of AT89C52
Void Delay_xus (uint t)
{
for(; T> 0; T -)
{
_nop_ ();
}
}
//write 595
/* * * * * * * * * * * * * * * * to * * * * * 595 * * * * * * * * * * * * * * * * * * * * * * * * */
Void write_595 (uchar date)//write 595
{
Uchar I;
For (I=0; I & lt; 8; I++) {
Sh=0; Ds=date & amp; 0 x80.
Sh=1; The date & lt; <=1;
}
}
//write instruction function
/* * * * * * * * * * * * * * * * writing instruction * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void Write_Instruction (uchar com)//write instructions
{
Write_595 (com). LCDRS=0;//written instructions
St=1; St=0;//595 output and EN output a high pulse
}
//write data function
/* * * * * * * * * * * * * * * * write * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void Write_Data (uchar dat)//write data
{
Write_595 (dat); LCDRS=1;//write data
St=1; St=0;//595 output and EN output a high pulse
}
//character shows the initial address Settings
Void LCD_SET_XY (uchar X, uchar Y)
{
Uchar address;
If (Y==0)
Address=0 x80 + X;//Y=0, said in the first row, according to the base address 0 x80
The else
Address=0 xc0 + X;//Y non-zero, the table is on the second line, according to the base address 0 xc0
Write_Instruction (address);//write instructions, set up according to the initial address
}
//at the beginning of the first line X Y columns show Wdata corresponds to a single character
Void LCD_write_char (uchar X, uchar Y, uchar Wdata)
{
LCD_SET_XY (X, Y);//write address
Write_Data (Wdata);//write the current character and displays a
}
//screen clearing function
Void LCD_clear (void)
{
Write_Instruction (0 x01);
Delay_xms (5);
}
//display initialization function
Void LCD_init (void)
{
X38 Write_Instruction (0);//8 bit interface, line 2, 5 * 7 dots
Delay_xms (5);
X38 Write_Instruction (0);
Delay_xms (5);
X38 Write_Instruction (0);
Write_Instruction (0 x08);//off display, do not show the cursor, the cursor is not flashing
Write_Instruction (0 x01);//clear screen
Delay_xms (5);
Write_Instruction x04 (0);//write a character, the whole screen does not move
//Write_Instruction x05 (0);//write a character, the whole screen moves to the right
//Write_Instruction x06 (0);//write a character, the whole screen does not move
//Write_Instruction x07 (0);//write a character, the whole screen left
Delay_xms (5);
//Write_Instruction x0b (0);//disable display (don't display character, only the back light)
X0c Write_Instruction (0);//display, cursor, flashing all closed
//Write_Instruction x0d (0);//display, don't show the cursor, but the cursor blink
//Write_Instruction x0e (0);//display, display a cursor, but the cursor blink
//Write_Instruction (0 x0f);//display, cursor, flashing all showed
}
//DS1302 initialization function
Void ds1302_init (void)
{
RST=0; Buy low//RST feet
SCK=0; Buy low//SCK feet
}
//to write a byte of data DS1302
Void ds1302_write_byte (uchar addr, uchar d)
{
Uchar I;
RST=1;//start DS1302 bus
//write to the target address: addr
Addr=addr & amp; 0 xfe;//the lowest position zero, 0 0 when writing, register to 1 read
For (I=0; I & lt; 8; I + +) {
If (addr & amp; {0 x01)
IO=1;
}
The else {
IO=0;
}
SCK=1;//produce the clock
SCK=0;
Addr=addr & gt;> 1;
}
//write data: d
For (I=0; I & lt; 8; I + +) {
If (d & amp; {0 x01)
IO=1;
}
The else {
IO=0;
}
SCK=1;//produce the clock
SCK=0;
D=d & gt;> 1;
}
RST=0;//stop DS1302 bus
}
//read a byte of data from a DS1302
Uchar ds1302_read_byte (uchar addr) {
Uchar I, temp.
RST=1;//start DS1302 bus
//write to the target address: addr
Addr=addr | 0 x01;//the lowest position, register 0 0 when writing, read to 1
For (I=0; I & lt; 8; I + +) {
If (addr & amp; {0 x01)
IO=1;
}
The else {
IO=0;
}
SCK=1;
SCK=0;
Addr=addr & gt;> 1;
}
//output data: temp
For (I=0; I & lt; 8; I + +) {
Temp=temp & gt;> 1;
If (IO) {
Temp |=0 x80;
}
The else {
Temp & amp;=0 x7f;
}
SCK=1;
SCK=0;
}
RST=0;//stop DS1302 bus
return temp;
}
//to write clock data DS302
Void ds1302_write_time (void)
{
Ds1302_write_byte (ds1302_control_add, 0 x00);//close the write protect
Ds1302_write_byte (ds1302_sec_add, 0 x80);//pause the clock
//ds1302_write_byte (ds1302_charger_add, 0 xa9);//a trickle charging
Ds1302_write_byte (ds1302_year_add, time_buf [1]);//in
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull