📄 ex_int0.c
字号:
//外部中断实验一
//功能:按键时产生一次外部中断(小灯闪烁三次)
#include <reg51.h>
unsigned char data buff_time;
unsigned char data wei;
void Delay() //the function of delay
{ unsigned int i;
for (i=0; i<25000; i++) ;}
void spark() //the function of sparking the lights for once
{Delay();
P1=0x00;
Delay();
P1=0xff;
}
void main()
{
IE=0;
IP=0X01;
TMOD=0x01; //set the timer's mode
TH0=(65536-5000)/256; //fill the timer0's higher register
TL0=(65536-5000)%256; //fill the timer0's lower register
IE=0x83; //EA=1,IT0=1
TR0=1; //start the timer for scanning the key
while(1){}//empty loop
}
void EXInt() interrupt 0 using 2 //external interupt for 3 times spark
{
EX0=0;
spark();
spark();
spark();
EX0=1;
}
void T0Int() interrupt 1 // timer0 interupt scan for the key
{
TH0=(65536-5000)/256; //fill the timer0's higher register
TL0=(65536-5000)%256; //fill the timer0's lower register
buff_time--;
wei=buff_time%6;
if (wei==5)
{P0=P0&0xfe;}
else if (wei==4)
{P0=P0&0xfd;}
else if (wei==3)
{P0=P0&0xfb;}
else if (wei==2)
{P0=P0&0xf7;}
else if (wei==1)
{P0=P0&0xef;}
else if (wei==0)
{P0=P0&0xdf;}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -