Request microcontroller clock design! Requirements: clock adjustable calendar adjustable alarm clock adjustable with temperature detection LCD1602 display with D

This program is better to use the 12864, more useful hope to help you

#include <reg51.h>

#include <intrins.h>

#include <stdlib.h>

#include <stdlib.h>

< p>#define uchar unsigned char

#define uint unsigned int

#include <intrins.h>

#define uchar unsigned char

##define uint unsigned int

# define uint unsigned int

uchar shijian[6]={0x1,0x1,0x0,0x2,0x5,0x8};

uchar zi[]={"hours, minutes, seconds"};

uchar j,key;

char z,z1;<

uchar m,mark=0,bz=0;

uint k=4000;

uchar i;

/* Port Definition*/

#define LCD_data P0 //data port

sbit inter_0=P3^2;

< p>sbit LCD_RS = P2^7; //register select input

sbit LCD_RW = P2^6; //LCD read/write control

sbit LCD_EN = P2^5; //LCD enable control

sbit LCD_PSB = P2^4; //serial/parallel mode control

void delay_1ms(uint x)

{

uint i,j;

for(j=0;j<x;j++)

for(i=0;i<110;i++);

}

/**************** ***************************************************/

/* */

/* Write command data to LCD */

/*RS=L, RW=L, E=High Pulse, D0-D7=Command Code. */

/* */

/*******************************************************************/

void write_cmd(uchar cmd)

{

LCD_RS = 0;

LCD_RW = 0;

LCD_EN = 0;

P0 = cmd;

delay_1ms(5);

LCD_EN = 1;

delay_1ms(5);

LCD_EN = 0 ;

}

/*******************************************************************/

/* */

/* Write display data to LCD */

/*RS=H. RW=L, E=High pulse, D0-D7=Data. */

/* */

/*******************************************************************/

void write_dat(uchar dat)

{

LCD_RS = 1;

LCD_RW = 0;

LCD_EN = 0;

P0 = dat;

delay_1ms(5);

LCD_EN = 1;

delay_1ms(5);

LCD_EN = 0 ;

}

/*********************************************************/

/* */

/* Sets the display position */

/* */

/******** *************************************************/

void lcd_pos(uchar X,uchar Y)

{

uchar pos;

if (X==0)

{ X=0x80;}

else if (X==1)

{X=0x90;}

else if (X==2)

{X=0x88;}

else if (X==3)

{X=0x98;}

pos = X+Y ;

write_cmd(pos); //display address

}

/*******************************************************************/

/* */

/* LCD initialization settings */

/* */

/*******************************************************************/

void lcd_init()

{

LCD_PSB = 1; //parallel mode

write_cmd(0x30); //basic command operation

delay_1ms(5);

write_cmd(0x0C); //display on, off cursor

delay_1ms(5);

{void lcd_init()

{void lcd_init()

{void lcd_init()

{void lcd_init()

{void lcd_init() write_cmd(0x01); //clear LCD display

delay_1ms(5);

}

/*********************************************************/

/ */

/* main program */

/* */

/*********************************************************/

main()

{ uchar x;

IT0=1;EX0=1;EA=1;

P1=0XF0;

TMOD=0X2;

TH0=0X6;

TL0=0X6;

EA=1;ET0=1;TR0=1;

i=0;

delay_1ms( 10); //delay

lcd_init();

lcd_pos(0,1);

write_dat(zi[0]);

write_dat(zi[1]);

lcd_pos(0,3);

write_dat (zi[2]);

write_dat(zi[3]);

lcd_pos(0,5);

write_dat(zi[4]);

write_dat(zi[5]);

while(1)

{

z=1;

z1=0;

P1=0XF0;

lcd_pos(0,0);

i = 0;

while(i<2)

{

write_dat(shijian[i]+0x30);

i++;

}

lcd_pos(0,2);

while(i<4)

{

write_dat(shijian[i]+0x30);

i++;

}

lcd_pos(0 ,4);

while(i<6)

{

write_dat(shijian[i]+0x30);

i++;

}

if(mark)

{TR0=0;

lcd_pos(0 ,0);delay_1ms(5);

write_cmd(0x0f);

delay_1ms(5);

bz=0;

while(!bz);

while(mark)

{

if(key= =12)

{z--;write_cmd(0x10);delay_1ms(5);write_cmd(0x10);delay_1ms(5);bz=0;if((2*(z-1)+(z1-1))==-3){for(x=0;x<6;x++){write_ cmd(0x14);delay_1ms(5);}z=3;z1=0;}}

else if(key==13)

{z++;write_cmd(0x14);delay_1ms(5);write_cmd(0x14);delay_1ms(5);bz= 0;if((2*(z-1)+(z1-1))>=5){for(x=0;x<6;x++){write_cmd(0x10);delay_1ms(5);}z=1;z1=0;}}

else if(key<=9)

{z1++; write_dat(key+48);delay_1ms(5);shijian[2*(z-1)+(z1-1)]=key;if((2*(z-1)+(z1-1)<5)&&(z1%2==0)){write_cmd(0x14);delay_1ms( 5);}else if(2*(z-1)+(z1-1)>=5){for(x=0;x<5;x++){write_cmd(0x10);delay_1ms(5);}z=1;z1=0;}bz=0;}

else if(key==15)

{ write_cmd(0x0c);delay_1ms(5);mark=0;}

while(!bz);

}

bz=0;

TR0=1;

}

}

/********** ***************************/

count0 (void) interrupt 1

{

k--;

if(k==0x0)

{++shijian[5];k=4000;

if (shijian[5]==0)

{shijian[5]=0x0;

++shijian[4];

if (shijian[4]==0x6)

{shijian[4]=0x0;

++shijian[3];

if (shijian[3]==0)

{shijian[3]=0x0;

++shijian[2];

if (shijian[2]==0x6)

{shijian[2]=0x0;

++shijian[ 1];

if((shijian[0]==0x0)&&(shijian[1]==0))

{shijian[1]=0x0;

++shijian[0];

}

else if((shijian[ 0]==0x1)&&(shijian[1]==0x2))

{shijian[1]=0x0;

shijian[0]=0x0;

}

}

}

}

}

}

}

}

} /p>

}

/*******************************************/

int_0(void) interrupt 0

{delay_1ms(15);

if(inter_0==0)

{uchar n=0,m=0,temp;

uchar scan[4]={0xfe,0xfd,0xfb,0xf7};

uchar table[4][4]={0x7e,0xbe,0xde,0xee,0x7d,0xbd,0xdd, 0xed,0x7b,0xbb,0xdb,0xeb,0x77,0xb7,0xd7,0xe7};

uchar num[4][4]={12,1,4,7,0,2,5,8,13,3,6,9,11,10,15,14};

while(n<4)

{P1=scan[n];temp=P1;m=0;

while(m<4)

{if(temp==table[n][m])

goto next;

else

m++;

}

n++;

}

next: key=num[n][m];

bz=1;

if(key==14)

mark=1;

}

P1=0XF0;

}