新闻中心

EEPW首页>嵌入式系统>设计应用> 80C51单片机程序(4)

80C51单片机程序(4)

作者: 时间:2016-11-22 来源:网络 收藏
//80C51单片机程序——中断的使用

#include //包含reg52.h头文件
#define uint unsigned int //宏定义uint的数据类型为unsigned int型
#define uchar unsigned char //宏定义uchar的数据类型为unsigned char型
sbit D1=P2^6;
sbit W1=P2^7;
sbit D2=P1^0;
uchar num;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //共阴数码管0-9
void delay(uint z); //声明延时子函数
void main()
{
EA=1;//开总中断
EX0=1;//开外部中断0
TCON=0x01; //打开跳变
W1=1; //给锁存器送高电位,打开锁存器

本文引用地址://m.amcfsurvey.com/article/201611/319718.htm

P0=0xea;
W1=0;//给锁存器送低电位,关闭锁存器
while(1)
{
for(num=0;num<10;num++)//循环10次,0-9显示数字
{
D1=1;//关闭数码管显示
P0=table[num];
D1=0;//打开位口
delay(1000);//延时程序
}
}
}

void delay(uint z)//含参延时子函数
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);//进入一次嵌套循环
}

void exter0()interrupt0//外部中断0程序
{
D2=0;
}



关键词:80C51单片机程

评论


技术专区

关闭