專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

單片機(jī)中斷模塊-中斷程序運(yùn)用

作者:佚名   來源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2011年03月27日   【字體:
#include<reg52.h>  //單片機(jī)的頭文件
#define uint unsigned int //宏定義無符號整型
#define uchar unsigned char//宏定義無符號字符型
#include<reg52.h>  //單片機(jī)的頭文件
#define uint unsigned int //宏定義無符號整型
#define uchar unsigned char//宏定義無符號字符型
char code b[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,
               0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff,
               0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00};//用十六進(jìn)制定義單片機(jī)P2口八盞燈得工作狀態(tài)
uchar code temp[]={0x80,0xe3,0x44,0x41,0x23,0x11,0x10,0xc3,0x00,0x01};//用十六經(jīng)
//用十六進(jìn)制定義數(shù)碼管0~9的數(shù)字顯示
uchar i;//全局定義
void delay(uint time) //延時(shí)函數(shù)
 {
   int k,l;
    for(k=0;k<=time;k++)
      for(l=0;l<50;l++);
 }
void main() //主函數(shù)
 {
   uchar a=0xf0;
   EA=1;//CPU總中斷位,為0時(shí),禁止所有中斷;為1時(shí),允許中斷
   IT0=1;// 外部中斷1觸發(fā)式選擇位,“IT1為外部1觸發(fā)式選擇位”
   EX0=1;//外部中斷允許中斷位,0時(shí)禁止中斷,1時(shí),允許中斷
    while(1)//死循環(huán):執(zhí)行中斷前的命令
     {
       for(i=0;i<16;i++)
        {
          P2=b[i]; //把定義的前16位的十六進(jìn)制的燈狀態(tài)賦給單片機(jī)的P2口
          delay(400);//調(diào)用延時(shí)函數(shù)
        }
     }
 }
void ext0() interrupt 0 using 0 //0觸發(fā)中斷請求
 {
   uchar j=1;
    while(1) //中斷執(zhí)行:執(zhí)行中斷后命令
     {
       for(i=17;i<38;i++)
         {
          P2=b[i];
          P1=temp[j];
          delay(400);
          j++;
          if(j==8)j=0;
         }
      }
 }
編后感:(本程序僅供參考),中斷就像一個(gè)函數(shù)的調(diào)用!
 
關(guān)閉窗口

相關(guān)文章