|
编程实现:正常情况下,P1口控制8个LED灯(低电平亮)常亮,当外部中断0中断时,P1口所接的8个LED灯流水一段时间;外部中断1中断时,P1口所接的8个LED灯间隔点亮一段时间。
#include <reg51.h>
unsigned char t0,t1;
void delay0_5s()
{
for(t0=0;t0<0x0a;t0++)
{
TH0=0x3c;
TL0=0xb0;
TR0=1;
while(!TF0);
TF0=0;
}
}
void delay_t(unsigned char t)
{
for(t1=0;t1<t;t1++)delay0_5s();
}
void int_0() interrupt 0
{ unsigned char n,j,k,l,m;
n=P1;
j=t0;
k=t1;
l=TH0;
m=TL0;
{
P1=0xfe;delay0_5s();
P1=0xfd;delay0_5s();
P1=0xfb;delay0_5s();
P1=0xf7;delay0_5s();
P1=0xef;delay0_5s();
P1=0xdf;delay0_5s();
P1=0xbf;delay0_5s();
P1=0x7f;delay0_5s(); // 提问:这段流水灯程序用数组或移位的方式应该怎么写?我想让这个中断执行两次,程序应该怎么写?
}
P1=n;
t0=j;
t1=k;
TH0=l;
TL0=m;
}
void int_1() interrupt 2
{ unsigned char n,j,k,l,m;
n=P1;
j=t0;
k=t1;
l=TH0;
m=TL0;
{
P1=0x00;
delay0_5s();
P1=0xff;
delay0_5s(); } //提问:我想让这个中断执行两次,程序应该怎么写?
P1=n;
t0=j;
t1=k;
TH0=l;
TL0=m;
}
void main()
{
EA=1;
EX0=1;
IT0=1;
EX1=1;
IT1=1;
TMOD=0x01;
while(1)
{
P1=0x00;
}
}
|
|