"Single Chip Microcomputer" Experiment-Experiment 2 MCS-51 External Interrupt Control Experiment

"Single Chip Microcomputer" Experiment-Experiment 2 MCS-51 External Interrupt Control Experiment

1. The purpose of the experiment

  1. Master the principle of interrupt control;
  2. Master the programming method of interrupt handler.

Two, knowledge points

(1) There are 5 interrupt sources in the 8051, two of which are external interrupt sources /INT0, /INT1, two timers T0 and T1 overflow request interrupts, and one on-chip serial port sends or receives interrupt sources TI and RI.
(2) The priority order of the 5 interrupt sources of 8051 has been determined by the hardware structure, from high to low:
/INT0→T0→/INT1→T1→RI or TI
(3) C51 compiler supports the interrupt service routine of 51 single-chip microcomputer . The format of writing interrupt service functions in C language is:
function type function name (formal parameter list) [interrupt n] [using m]
where n after interrupt is the interrupt number, and the value range is 0 to 4. The m in using represents the working register group number used (if not declared, the default value group 0 is used)

3. Experimental procedures and requirements

  1. Use Proteus to draw a schematic diagram of the circuit.
  2. Use Keil C51 to write source code, compile and generate Hex file.
  3. Run the program, observe and analyze the experimental results.
  4. Write an experiment report.

Four, experiment content

(1) Use external interrupt /INT0 to control the blinking of the LED pattern connected to port P1.

(2) Use external interrupt /INT1 to count the number of interrupts, and send the statistical results to the 8-bit LED display of port P1.

1. Code

The following code combines (1) and (2) into a piece of code, and uses external interrupt /INT0 to control the blinking of the LED pattern connected to port P1. Use external interrupt/INT1 to count the number of external interrupt/INT0 interrupts

#include<reg51.h>

char led[]={
    
    0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
bit dir=0,run=0;
void delay(unsigned int time);
int num=0;

key() interrupt 0{
    
    
	char i;
	for(i=0;i<=7;i++){
    
    
			P1=led[i];
			delay(200);
		}
	P1=0xff;
	num++;
}

key1() interrupt 2{
    
    
	P1=~num;
}

void main(){
    
    
	IT0=1;
	IT1=1;
	EX0=1;
	EX1=1;
	EA=1;
	while(1){
    
    
	}
}

void delay(unsigned int time){
    
    
	unsigned int j=0;
	for(;time>0;time--)
	for(j=0;j<125;j++);
}

2. Circuit diagram

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44652589/article/details/114661124