新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 單片機中斷模塊-中斷程序運用

單片機中斷模塊-中斷程序運用

作者: 時間:2012-08-24 來源:網(wǎng)絡(luò) 收藏

#includereg52.h> //的頭文件

本文引用地址:http://butianyuan.cn/article/170994.htm

#define uint unsigned int //宏定義無符號整型

#define uchar unsigned char//宏定義無符號字符型

#includereg52.h> //的頭文件

#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};//用十六進制定義P2口八盞燈得工作狀態(tài)

uchar code temp[]={0x80,0xe3,0x44,0x41,0x23,0x11,0x10,0xc3,0x00,0x01};//用十六經(jīng)

//用十六進制定義數(shù)碼管0~9的數(shù)字顯示

uchar i;//全局定義

void delay(uint time) //延時函數(shù)

{

int k,l;

for(k=0;k=time;k++)

for(l=0;l50;l++);

}

void main() //主函數(shù)

{

uchar a=0xf0;

EA=1;//CPU總位,為0時,禁止所有;為1時,允許

IT0=1;// 外部中斷1觸發(fā)式選擇位,“IT1為外部1觸發(fā)式選擇位”

EX0=1;//外部中斷允許中斷位,0時禁止中斷,1時,允許中斷

while(1)//死循環(huán):執(zhí)行中斷前的命令

{

for(i=0;i16;i++)

{

P2=b[i]; //把定義的前16位的十六進制的燈狀態(tài)賦給單片機的P2口

delay(400);//調(diào)用延時函數(shù)

}

}

}

void ext0() interrupt 0 using 0 //0觸發(fā)中斷請求

{

uchar j=1;

while(1) //中斷執(zhí)行:執(zhí)行中斷后命令

{

for(i=17;i38;i++)

{

P2=b[i];

P1=temp[j];

delay(400);

j++;

if(j==8)j=0;

}

}

}

編后感:(本僅供參考),中斷就像一個函數(shù)的調(diào)用!



關(guān)鍵詞: 中斷 運用 程序 模塊 單片機

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉