新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 单片机中断模块-中断程序运用

单片机中断模块-中断程序运用

作者:时间:2012-08-24来源:网络收藏

#includereg52.h> //的头文件

本文引用地址:http://www.eepw.com.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口八盏灯得工作状态

uchar code temp[]={0x80,0xe3,0x44,0x41,0x23,0x11,0x10,0xc3,0x00,0x01};//用十六经

//用十六进制定义数码管0~9的数字显示

uchar i;//全局定义

void delay(uint time) //延时函数

{

int k,l;

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

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

}

void main() //主函数

{

uchar a=0xf0;

EA=1;//CPU总位,为0时,禁止所有;为1时,允许

IT0=1;// 外部中断1触发式选择位,“IT1为外部1触发式选择位”

EX0=1;//外部中断允许中断位,0时禁止中断,1时,允许中断

while(1)//死循环:执行中断前的命令

{

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

{

P2=b[i]; //把定义的前16位的十六进制的灯状态赋给单片机的P2口

delay(400);//调用延时函数

}

}

}

void ext0() interrupt 0 using 0 //0触发中断请求

{

uchar j=1;

while(1) //中断执行:执行中断后命令

{

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

{

P2=b[i];

P1=temp[j];

delay(400);

j++;

if(j==8)j=0;

}

}

}

编后感:(本仅供参考),中断就像一个函数的调用!



评论


相关推荐

技术专区

关闭