Application of single chip microcomputer interrupt

Source: Internet
Author: User

51 single-chip microcomputer:

P3.2 PIN is INT0 interrupt

P3.3 PIN is INT1 interrupt

Button P3.2 P3.3

Button low-level trigger:

while (pb0==0);

Delay ();

#include <reg51.h>#defineSEG P0//define seven-section display to Port 0sbit LED= p2^0;//define the LED light to connect to the P2.0Sbit com = p1^0;//Digital tube com PortSbit OC = p1^1;//Define 573 latch enable port, I am using the 573 drive 7 segment Digital tube voidDELAY10MS (intx);//declaring a delay function 10ms * x;sbit PB0=p3^2;//Button 0Sbit pb1=p3^3;//Button 1unsignedCharCode tab[Ten]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67};//Common CathodeMain () {OC=0;//latching 0, light digital tubecom =0;//Light segEA =1;//Total InterruptionEX0 =1;//External Interrupt INT0EX1 =1;//External Interrupt INT1TR0 =1;//Run int 0 InterruptTR1 =1;//Run INT1 InterruptTCON =0x05;//set the signal trigger mode to be negative edge trigger     while(1)     {            inti;  for(i=0;i<Ten; i++)//showing 0-9 (of previous){seg=Tab[i]; Delay10ms ( +);//Delay 0.4s

} } } voidMy_int0 (void) Interrupt0 //INT 0{inti; while(pb0==0); Delay10ms ( -); for(i=9; i>=0; i--)//For Loop display 9-0 (Next number){SEG=tab[i];//display Digital to seven-section displayDELAY10MS ( +);//Delay 0.4s } } voidMy_int1 (void) Interrupt2 //INT 1{inti; while(pb1==0); Delay10ms ( -); for(i=0;i<Ten; i++) {LED=0; Delay10ms ( -); LED=1; Delay10ms ( -); }}/*delay function, delay approx. x*1ms*/voidDELAY10MS (intX//delay function Start{ inti,j; for(i=0; i<x;i++)//count x times, delay x*10ms for(j=0;j< -; j + +);//Count 1200 times, delay 10ms 1200*8us}

Application of single chip microcomputer interrupt

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.