📄 main.c
字号:
#include <AT89X51.H>
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char dispcount=0; //计数
sbit gewei=P1^3; //个位选通定义
sbit shiwei=P1^2; //十位选通定义
void Delay(unsigned int tc) //延时程序
{
while( tc != 0 )
{
unsigned int i;
for(i=0; i<100; i++);
tc--;
}
}
void ExtInt0() interrupt 0 //中断服务程序
{
dispcount++; //每按一次中断按键,计数加一
if (dispcount==100) //计数范围0-99
{dispcount=0;}
}
void LED( ) //LED显示函数
{
if(dispcount>=10) //显示两位数
{
shiwei=0;
P0=table[dispcount/10];
Delay(8);
shiwei=1;
gewei=0;
P0=table[dispcount%10];
Delay(5);
gewei=1;
}
else //显示一位数
{
shiwei=1;
gewei=0;
P0=table[dispcount];
Delay(8);
}
}
void main()
{ TCON=0x01; //下降沿触发
IE=0x81; //开总中断和允许外部中断
while(1) //循环执行
{
LED(); //调用显示函数
}
}
/*********************************************************************
在程序在硬件运行过程中,有时候按一下键会加几个数,是因为没有去除按键干扰
请您想一想怎么消除抖动.
/*********************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -