|
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
void bh(uchar x);
//uchar i,j,k,l;
uchar x;
void zd_init()
{
TMOD= 0X11;
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
EA = 1;
ET0= 1;
TR0= 1;
EX0=1;
IT0=0;
}
/*void wbzd_init()
{
TMOD=0X10;
EA=1;
EX0=1;
IT0=0;
} */
void delay_ms(uint ms) // 延时子程序
{
uint a,b;
for(a=ms;a>0;a--)
for(b=123;b>0;b--);
}
void main()
{
zd_init();
//wbzd_init();
while(1)
{
bh(x);
}
}
void bh(uchar n)
{
if(n>0&&n<25)P1=0x1e;
if(n>=25&&n<30)P1=0x2e;
if(n>=30&&n<55)P1=0x33;
if(n>=55&&n<60)P1=0x35;
}
void zd() interrupt 1
{
uint der,sec;
TH0 = (65536-50000)/256;
TL0 = (65536-50000)%256;
if(++der==20)
{
der=0;
x++;
if(++sec>=60)
{
sec=0;
}
}
}
void wbzd() interrupt 0
{
P1=0x36;
delay_ms(10000);
}
|
|