微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > 51单片机中断执行

51单片机中断执行

时间:10-02 整理:3721RD 点击:
#include <reg52.h>
typedef unsigned int uint16;     
typedef unsigned char uint8;
uint8 code num[] = {0xc0,0xf9,0xa4,0xb0,   // //用数组来表示数码管真值表0-F;
      0x99,0x92,0x82,0xf8,
      0x80,0x90,0x88,0x83,
      0xa7,0xa1,0x86,0x8e};
sbit ENLED = P1^4;    //38译码器的位声明;
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit  LED  = P0^0;
uint8 lednum[6] = {0};
uint8 j = 0;
uint16 counter = 0;
void main (void)
{  
  unsigned long m = 0;
  ADDR3 = 1;
  ENLED = 0;
     P0 = 0XFF;    //P0的初始化;
  TMOD = 0X01;     //设置定时器为模式1;
  TH0 = 0XFC;
  TL0 = 0X67;   
     TR0 = 1;        //打开定时器0;
  EA = 1;
  ET0 = 1;   
  while (1)
   {
    if (counter ==1000) //计时1s;
    {
     counter = 0;
     m++;  
     lednum[0] = m%10;  
     lednum[1] = m/10%10;
     lednum[2] = m/100%10;
     lednum[3] = m/1000%10;
     lednum[4] = m/10000%10;
     lednum[5] = m/100000%10;
    }
   }
}
void InterruptTime0() interrupt 1
{
         TH0 = 0XFC;
              TL0 = 0X67;
     counter++;
     P0 = 0xFF;
     switch (j)       //数码管动态刷新;
    {
     case 0: ADDR0 = 0;ADDR1 = 0;ADDR2 = 0;j++;P0 = num[lednum[0]];break;
     case 1: ADDR0 = 1;ADDR1 = 0;ADDR2 = 0;j++;P0 = num[lednum[1]];break;
     case 2: ADDR0 = 0;ADDR1 = 1;ADDR2 = 0;j++;P0 = num[lednum[2]];break;
     case 3: ADDR0 = 1;ADDR1 = 1;ADDR2 = 0;j++;P0 = num[lednum[3]];break;
     case 4: ADDR0 = 0;ADDR1 = 0;ADDR2 = 1;j++;P0 = num[lednum[4]];break;
     case 5: ADDR0 = 1;ADDR1 = 0;ADDR2 = 1;j = 0;P0 = num[lednum[5]];break;
     default : break;
    }



}

上面程序怎么执行的,中断函数什么时候开始执行的?新手求解释,谢谢!

还是不懂

中断发生在任何时刻。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top