当前位置:网站首页>Basic operation of external interrupt (keil5)

Basic operation of external interrupt (keil5)

2022-07-05 07:18:00 After reading thousands of books, you can pick them up and put

I didn't press s5, Always execute the main program (L1 Keep flashing ), Press down s5, The main program is suspended , Execute the contents of the interrupt service function (L2 bright ,L2 After extinction ), Continue the main program just now (L1 Keep flashing ).

#include <STC15F2K60S2.H>
#include <intrins.h>
sbit L2=P0^1;
sbit L1=P0^0;
void initsystem()
{
    
	P2=0xbf&(P2|0xe0);
	P0=0x00;
	P2=0x1f&(P2|0xe0);
	P2=0x9f&(P2|0xe0);
	P0=0xff;
	P2=0x1f&(P2|0xe0);
}
void Delay500ms()		//@11.0592MHz
{
    
	unsigned char i, j, k;

	_nop_();
	_nop_();
	i = 22;
	j = 3;
	k = 227;
	do
	{
    
		do
		{
    
			while (--k);
		} while (--j);
	} while (--i);
}
void LED()
{
    
	L1=0;
	Delay500ms();
	L1=1;
	Delay500ms();
}
void Init_Timer()
{
    
	IT0=1;
	EX0=1;
	EA=1;
}
void Iterrupt1() interrupt 0
{
    
	L2=0;
	Delay500ms();
	Delay500ms();
	Delay500ms();
	Delay500ms();
	L2=1;
}
void main()
{
    
	Init_Timer();
	initsystem();
	P2=0x9f&(P2|0xe0);
	while(1)
	{
    
		LED();
	}
}
原网站

版权声明
本文为[After reading thousands of books, you can pick them up and put ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140558148576.html