|
#include
#define uchar unsigned char;
sbit p1=P0^4;//蜂鸣器地址
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x80,
0xc6,0xc0,0x86,0x8e
};
uchar num,t;
void delay(int z);
void main()
{
num=0;
t=0;
TMOD=0x01;//设置定时器0为工作方式
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;//定时
EA=1;//开总中断
EX1=1;//开外部中断1
ET0=1;//开定时器0中断
TR0=1;//启动定时器
//IP=0x04;//设置外1中断优先(我没执行)
P1=table[0];
while(1)
{
if(t==20)
{
t=0;
num++;
if(num==16)
num=0;
P1=table[num];
}
}
}
void delay(int z)
{
int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void ex1() interrupt 1//定时中断
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t++;
}void ex2() interrupt 2//外部中断1
{
p1=0;
delay(1000);
p1=1;
}
在上边的程序中 我没把外部中断1设成优先。那为什么上面的程序给外部中断1低电平它会优先于timer0呢?timer0应该比外部中断1优先啊!
新手入门,请教高手
|
|