📄 text1.c
字号:
#include<reg52.h>
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char dispcount=0; //计数
sbit gewei=P2^0; //个位选通定义
sbit shiwei=P2^1; //十位选通定义
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()
{
P3=0x0F;
TCON=0x01; //中断设置
IE=0x81;
while(1) //循环执行
{
LED(); //只须调用显示函数
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -