51单片机的P1口接一个共阳八段数码管,INT0引脚有外部脉冲输入,当脉冲计数到100时数码管显示数字加1,数码管显示值范围是0-9,试画出51单片机与外设的连接图并编程实现以上要求。
proteus的连接图:
频率是200Hz,即0.5s改变一次
源代码:
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar num[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//0~9的共阳极断码表
uchar i=0;
uchar count=0;//脉冲次数
void main()
{
P1=num[i];
EA=1;
EX0=1;
IT0=1;//使用外部中断0,跳沿触发方式
while(1);
}
void int0() interrupt 0
{
count++;
if(count==100){
i=++i%10;
P1=num[i];
count=0;
}
}
注:Proteus导线旁的方块提示端口状况,红色高电平,蓝色低电平