Current location - Music Encyclopedia - Chinese History - Historical sshi
Historical sshi
# include & ltreg52.h & gt

# Define uchar unsigned characters

# Define uint unsigned integer

sbit dula=p2^6;

sbit wela=p2^7;

sbit lcden=p3^4;

sbit lcdrs=p3^5;

sbit key 1=p3^0;

sbit key2=p3^ 1;

sbit key3=p3^2;

//sbit key4=p3^3;

sbit key=p3^7;

Void display ();

void delay ms(uint z);

void keyscan();

void init();

void write _ com(uchar com);

void write _ data(uchar date);

uchar num,num 1,num 2; num3,num4

uchar sshi、sge、fshi、fge、mshi、mge

uint temp = 0;

Void init() // initialization

{

Dura = 0;

wela = 0;

TMOD = 0x 0 1;

TH0 =(65536-45872)/256;

th 1 =(65536-45872)% 256;

EA = 1;

ET0 = 1;

TR0 = 1;

LC den = 0;

write _ com(0x 38);

write _ com(0x0c);

write _ com(0x 06);

write _ com(0x 0 1);

}

Void write _ com(uchircom)// write instruction

{

LCD RS = 0;

P0 = com

Delems (5);

LC den = 1;

Delems (5);

LC den = 0;

}

Void write_data(uchar date)// Write data.

{

LCD RS = 1;

P0 = date;

Delems (5);

LC den = 1;

Delems (5);

LC den = 0;

}

Void delayms(uint z)// delay

{

uint i,j;

for(I = z; I>0; I-)

for(j = 1 10; j & gt0; j-);

}

Void display()// LCD display

{

write _ com(0x 80);

write _ data(sshi+48);

delay ms( 1);

write _ com(0x 80+0x 0 1);

write _ data(sge+48);

delay ms( 1);

write _ com(0x 80+0x 02);

write _ data(':');

delay ms( 1);

write _ com(0x 80+0x 03);

write _ data(fshi+48);

delay ms( 1);

write _ com(0x 80+0x 04);

write _ data(fge+48);

delay ms( 1);

write _ com(0x 80+0x 05);

write _ data(':');

delay ms( 1);

write _ com(0x 80+0x 06);

write _ data(mshi+48);

delay ms( 1);

write _ com(0x 80+0x 07);

write _ data(mge+48);

delay ms( 1);

}

void keysscan()

{

key = 0;

if(key 1==0)

{

Delems (5);

if(key 1 = = 0);

{

And (! key 1);

temp++;

TR0 = 0;

write _ com(0x0f);

}

}

Switch (temperature)

{

Case 1:

if(key2==0)

{

Delems (5);

if(key 2 = = 0);

{

And (! Key 2)

num 1++;

if(num 1 = = 60)num 1 = 0;

}

}

if(key3==0)

{

Delems (5);

if(key3==0)

{

And (! Key 3)

num 1-;

if(num 1 = =- 1)num 1 = 0;

}

}

Break;

Case 2:

{

if(key2==0)

{

Delems (5);

if(key2==0)

{

And (! key 2);

num 2++;

if(num 2 = = 60)num 2 = 0;

}

}

if(key3==0)

{

Delems (5);

if(key3==0)

{

And (! key 3);

num 2-;

if(num 2 = =- 1)num 2 = 0;

}

}

}

Break;

Case 3:

{ if(key2==0)

{

Delems (5);

if(key2==0)

{

And (! key 2);

num 3++;

if(num 3 = = 60)num 3 = 0;

}

}

if(key3==0)

{

Delems (5);

if(key3==0)

{

And (! key 3);

num 3-;

if(num 3 = =- 1)num 3 = 0;

}

}

}

Break;

Case 4:

{

temp = 0;

TR0 = 1;

write _ com(0x 08);

}

}

}

Voidt0 _ time () interrupt 1// Clock 0 interrupt

{

num++;

TH0 =(65536-45872)/256;

th 1 =(65536-45872)% 256;

If (Quantity ==20)

{

num = 0;

num 1++;

if(num 1==60)

{

num 1 = 0;

num 2++;

}

mshi = num 1/ 10;

mge = num 1% 10;

if(num2==60)

{

num 2 = 0;

num 3++;

}

fshi = num 2/ 10;

fge = num 2% 10;

if(num3==24)

{

num 3 = 0;

//num 4++;

}

sshi = num 3/ 10;

sge = num 3% 10;

//if(num4)

Display ();

}

}

void main()

{

init();

while( 1)

{

keys scan();

}

}