|
#include<reg52.h>
#include<intrins.h>
typedef unsigned char uchar;
typedef unsigned int uint;
sbit P20=P2^0;
sbit P21=P2^1;
sbit P32=P3^2;
sbit P33=P3^3;
sbit BEEP=P1^5;
uchar code Led_Table[12]= { 0x3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F,0x40,0x00 };
uchar cnt,n,t=1;
uint i;
//延時函數
void delay(uint i)
{ uchar j;
for(i;i>0;i--)
for(j=0;j<100;j++)
;
}
//蜂鳴器
void beep()
{
unsigned char i;
for (i = 0; i < 180; i++)
{
delay(10);
BEEP = !BEEP; //BEEP取反
}
BEEP = 1; //關閉蜂鳴器
delay(10);
}
void main(void)
{ BEEP=1;
IT0=0; //實驗箱IT位必須設置成0 才合適,但是仿真IT位是0是1都不影響
EX0=1;
IT1=0;
EX1=1;
EA=1;
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;ET0=1;
//TR0=0;
n=0;
cnt=0;
P20=P21=1;
P20=1;
//數碼管刷新
while(1)
{
P20=0;
P0=Led_Table[n/10];
delay(10);
P20 = 1;
P21=0;
P0=Led_Table[n%10];
delay(10);
P21 = 1;
if(cnt==20)
{
cnt=0;n++;
}
if(t==0)
{TR0=0;t=1;}
if(n==60)
{beep();n=0;}
}
}
void int0() interrupt 1
{EX0=0;
//if (P32==0)
// for (i=0;i<5000;i++);
while(P32==0);
TR0=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
cnt++;
EX0=1;
}
void int1() interrupt 2
{EX1=0;
//if (P33==0)
// for (i=0;i<5000;i++);
while(P33==0);
t=0;
EX1=1;
}
|
|