当前位置:网站首页>MCU case -int0 and INT1 interrupt count

MCU case -int0 and INT1 interrupt count

2022-07-05 22:21:00 kdnnnd

Single chip microcomputer case

 combination proteus and keil

INT0 And INT1 Interrupt count

Schematic diagram

 Insert picture description here

Program
/*  name :INT0 and INT1 Interrupt count   explain : Press the count key K1 The count value is displayed on the right nixie tube ,  Press the count key K2 The count value is displayed on the left nixie tube ,  Press the reset key K3,K4 Nixie tube reset  */
#include<reg51.h>
#include<intrins.h>
#define INT8U unsigned char
#define INT16U unsigned int 

sbit K3=P3^4;// Zero clearing 
sbit K4=P3^5;
// Co anode 0-9 Digital tube segment code table 
code INT8U CA_Table[]=
{
    
	0xC0,0xF9,
	0xA4,0xB0,
	0x99,0x92,
	0x82,0xF8,
	0x80,0x90,
	0xFF// Black screen 
};

code INT8U scan_bits[]=
{
    
	0x20,0x10,
	0x08,0x04,
	0x02,0x01
};
// Display buffer of two sets of counts , front 3 For a group , after 3 A group of 
INT8U show_buffer[]=
{
    
	0,0,0,
	0,0,0
};
INT16U count_a=0;
INT16U count_b=0;

// Time delay 
void delay_ms(INT16U x)
{
    
	INT8U t;
	while(x--)
	{
    
		for(t=0;t<120;t++);
	}
}
// The nixie tube displays the count value 
void refresh_show()
{
    
	INT8U i;
	// decompose count_a
	show_buffer[5]=count_a/100;
	show_buffer[4]=count_a%100/10;
	show_buffer[3]=count_a%10;

	if(show_buffer[5]==0)// The high position is 0 Time does not show 
	{
    
		show_buffer[5]=10;
		// The high position is 0 when , The second is 0, It doesn't show 
		if(show_buffer[4]==0)
			show_buffer[4]=10;
	}

	// decompose count_b
	show_buffer[2]=count_b/100;
	show_buffer[1]=count_b%100/10;
	show_buffer[0]=count_b%10;

	if(show_buffer[2]==0)// The high position is 0 Time does not show 
	{
    
		show_buffer[2]=10;
		// The high position is 0 when , The second is 0, It doesn't show 
		if(show_buffer[1]==0)
			show_buffer[1]=10;
	}


	for(i=0;i<6;i++)
	{
    
		P0=0xFF;// Temporarily close the segment code 
		P2=scan_bits[i];// Bit code 
		P0=CA_Table[show_buffer[i]];// Segment code 
		delay_ms(1);
	}

}
void main()
{
    
	IT0=1;// Falling edge trigger 
	IT1=1;
	PX0=1;// set priority 
	IE=0x85;// allow INT0,INT1 interrupt 

	while(1)
	{
    
		if(!K3)// Zero clearing 
			count_a=0;
		if(!K4)// Zero clearing 
			count_b=0;
		refresh_show();// Continue to refresh the display 
	}
}

//INT0 Interrupt function 
void ex_int0() interrupt 0
{
    
	EA=0;// No interruptions 
	delay_ms(10);// Desquamation 
	count_a++;// The count is incremented 
	EA=1;// Open the interrupt 
}
//INT1 Interrupt function 
void ex_int1() interrupt 2
{
    
	EA=0;// No interruptions 
	delay_ms(10);// Desquamation 
	count_b++;// The count is incremented 
	EA=1;// Open the interrupt 
}
原网站

版权声明
本文为[kdnnnd]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140435011515.html