|
/********************************AT89C52???3??D??************************/
#include<reg52.h> //??o????????treg52.h
#define uchar unsigned char //?T???o???????D???????????????auchar
#define uint unsigned int
sbit biaozhun= P1^0;//???????????
sbit jingji = P1^1;
sbit dandu = P1^2;
sbit paishuiled= P1^3;
sbit qiangxi = P1^4;
sbit ruoxi = P1^5;
sbit xidi = P1^6;
sbit piaoxi = P1^7;
sbit tuoshui = P2^0;
sbit jinshui = P2^2;
sbit paishui = P2^3;
sbit zz = P2^4;
sbit fz = P2^5;
sbit baojing = P2^1;
/********************************????????????************************/
sbit CX_key = P3^0;
sbit QR_key = P3^1;
sbit SW_key = P3^6;
sbit GKG_key = P3^7;
/********************************?????????????????************************/
uchar tt,num,qr,qidong;
uint tt1=0;
bit XDshanshuo;
bit PXshanshuo;
bit TSshanshuo;
bit BJshanshuo;
/********************************????????????************************/
void delay(uint i)
{
uchar x; //,a,b,c
while(i--)
T2CON=0X01;
for(x=0;x<20;x++);//?????????????????5??
{
TH2=0x3c; //????????????????3????
TL2=0xb0;
TR2=1;
while(!TF2); //2?????????y?????????3?
TF2=0; //???????????????? ,???????????¨??3?????????TF2?????
while(!qidong); //?Y???????
}
}
/********************************???????o????************************/
void delayms(uint i)
{
uchar x;
while(i--)
for(x=0;x<110;x++);
}
/*******************************?????????DD??????************************/
void biaozhunfangshi() //???????????????DD
{
jinshui=0; //???????a
delay(4); //???????
jinshui=1; //????1????
xidi=0; //????????a
TR1=1; XDshanshuo=1; //???????????????1???????????
delay(20); //???????
xidi=1; //????????a
TR1=0; XDshanshuo=1; //1??????????????,???????????
zz=0; //?y??a???a
fz=0; //?????a???a
paishui=0; BJshanshuo=1; //???????a
delay(2); //???????
paishui=1; //1????????
jinshui=0; //???a????
delay(4); //???????
jinshui=1; BJshanshuo=0; //1????????
piaoxi=0; //???a??????
TR1=1; PXshanshuo=1; //???a??????????1??????????
delay(20); //???????
piaoxi=1; //1??????????
TR1=0; PXshanshuo=0; //1??????????????1.??????????
zz=0; //???a?y??a
fz=0; //???a?????a
paishui=0; BJshanshuo=1; //???a????
delay(2); //???????
paishui=1; //1????????
jinshui=0; //???a????
delay(4); //???????
jinshui=1; BJshanshuo=0; //1????????
piaoxi=0; //???a??????
TR1=1; PXshanshuo=1; //???a??????????1
delay(20); //???????
piaoxi=1; //1??????????
TR1=0; PXshanshuo=0; //1??????????????1
zz=0; //???a?y??a
fz=0; //???a?????a
paishui=0; BJshanshuo=1; //???a????
delay(2); //???????
paishui=1; //1????????
tuoshui=0;
TSshanshuo=1; //???a?????
delay(2); //???????
tuoshui=1;
TSshanshuo=0; //1?????????
biaozhun=1; //1???????????
}
/****************************?-????DD??????************************/
void jingjifangshi()//?-????????
{
jinshui=0; //???a????
delay (4); //???????
jinshui=1; //1????????
xidi=0; //???a?????
TR1=1; //???a??????????1
XDshanshuo=1; //???a???????????
delay(30); //???????
xidi=1; //1?????????
TR1=0; XDshanshuo=0; //1??????????????1
zz=0; //???a?y??a
fz=0; //1?????????a
paishui=0; //???a????
delay(2); //???????
paishui=1; //1????????
jinshui=0; //???a????
delay(4); //???????
jinshui=1; //1????????
piaoxi=0; //???a??????
TR1=1; PXshanshuo=1; //???a??????????1
delay(20); //???????
piaoxi=1; //1??????????
TR1=0; PXshanshuo=0; //1??????????????1
zz=0; //?y??a
fz=0;//?????a
paishui=0; //???a????
delay(2); //???????
paishui=1; //1????????
tuoshui=0; TSshanshuo=1; //???a?????
delay(2); //???????
tuoshui=1; TSshanshuo=0; //1?????????
jingji=1; //1????????
}
/***************************************************************/
void dandufangshi() //????????????
{
jinshui=0; //???a????
delay(4); //???????
jinshui=1; //1????????
xidi=0; XDshanshuo=1; //???a?????
TR1=1; //???a??????????1
delay(30); //???????
xidi=1; //1?????????
TR1=0; XDshanshuo=0; //1??????????????1
zz=0; //?y??a
fz=0; //?????a
dandu=1;
}
/*******************************??????DD??????************************/
void paishuifangshi() //??????????
{
paishui=0; //???a????
delay(2); //???????
paishui=1; //1????????
tuoshui=0; TSshanshuo=1; //???a?????
delay(2); //???????
tuoshui=1; TSshanshuo=1; //???a?????
paishuiled=1;
}
/*******************************??????D??3??D??************************/
void QiangRuoQieHuan() //??????D??????3??D??
{
switch(qr)
{
case 1:{qiangxi=0;ruoxi=1;}break; //?????
case 2:{qiangxi=1;ruoxi=0;}break; //??????
case 3:{qr=1;}break; //?????
}delayms(1);
}
/*******************************???o????y************************/
void main()
{
EA=1; //???a?D?????????D????
EX0=1; //???a??a2??D??0???D????
IT0=1; //????????a2??D???a????????????顤????
EX1=1; //??a2??D??1?D??
IT1=1; //????????????????顤????
TMOD=0x11; //1????????????????y
TH0=(65536-50000)/256; //???????3????
TL0=(65536-50000)%256; //???????3????
ET0=1; //T0?D?????D????
TR0=1; //???????????????
TH1=(65536-50000)/256; //???????3????
TL0=(65536-50000)%256; //???????3????
ET0=1; //T0?D?????D????
TR0=1; //???????????????
TH1=(65536-50000)/256; //???????3????
TL0=(65536-50000)%256; //???????3????
ET1=1; //T1?D?????D????
T2CON=0x01; //??????????21??????????1
num=1;
qr=1; //1?????????
qidong=0; //???a?????
while(1)
{
QiangRuoQieHuan(); //??????D??????3??D??
switch(num) //3??D??LED?????
{
case 1:{biaozhun=0;jingji=1;dandu=1;paishuiled=1;}break; //???????
case 2:{biaozhun=1;jingji=0;dandu=1;paishuiled=1;}break; //?-??
case 3:{biaozhun=1;jingji=1;dandu=0;paishuiled=1;}break; //??????
case 4:{biaozhun=1;jingji=1;dandu=1;paishuiled=0;}break; //????
}delayms(1);
if(qidong==1)
{
while(1)
{
switch(num) //3??D?????????D??
{
case 1:{biaozhunfangshi();}break; //?????????????
case 2:{jingjifangshi();}break; //?-????????
case 3:{dandufangshi();}break; // ????????????
case 4:{paishuifangshi();}break; //??????????
}delayms(1); return;
}
}
}
}
/*******************************?D??*********************************/
void int0() interrupt 0 //??DD/?Y????
{
qidong++; //?????
if(qidong==2) //???1?????????a
{qidong=0;TR1=0;zz=0;fz=0;} //????????a
}
void int1() interrupt 2 { //???a1?
EA=0; //1?????D?????????D????
TR0=0; //1??????????????0
TR0=1; //???????????????1
zz=0; //???a?y??a
fz=0; //???a?????a
TR2=0; //1??????????????2
TF2=0; } //????????????????,???????????¨??3?????????TF2?????
void time0() interrupt 1 //???????????D??0?D??????D??o?1
{
TH0=(65536-50000)/256; //???????3????
TL0=(65536-50000)%256; //???????3????
tt++;
if(QR_key==0) //??????D???a1?
{
delayms(5); //???????
if(QR_key==0) //???1???????a1?????????
{
qr+=1; //?????
}
while(!QR_key);
}
if(CX_key==0) //3??D?????????
{
delayms(5); //???????
if(CX_key==0) //???1??????3??D?????
{num++;
if(num==5)num=1;
}
while(!CX_key);
}
/*******************************???a1?************************/
if(GKG_key==0) //???a1?
{
{
while(!GKG_key)
{TR1=0;zz=0;fz=0;} //???a??????????1 ?y??a??顤???a???a
TR1=1; //???a??????????1
}
if(tt==14) //LED 0.7s ??????
{
tt=0;
{
if(XDshanshuo==1) //???1???????????
{xidi=!xidi;} //2??????
if(PXshanshuo==1) //???1???????????
{piaoxi=!piaoxi;} //2???????
if(TSshanshuo==1) //???1???????????
{tuoshui=!tuoshui;} //2??????
}
}
}
}
void time1() interrupt 3 //???????????D??1?D??????D??o?3
{
TH1=(65536-50000)/256; //???3????
TL1=(65536-50000)%256; //???3????
if(tt1==0) //???????y??a
{
zz=0;
fz=1;
}
if(tt1==120) //6??o?????????????1
{
zz=1; //???????????1
fz=1;
}
tt1++; //?????????D?
if(tt1==200) //4??o?????????????a
{
zz=1; //?????a
fz=0;
}
if(tt1==320) //6??o?????????????1
{
zz=1; //??????2???a
fz=1;
}
if(tt1==400) //4??o?????????y??a
{
tt1=0; //???????y??a
}
}
老鐵,程序最好看懂呢
|
|