📄 计数器1.c
字号:
/*-----------------------------------------------
名称:按键计数器
日期:2009.5
修改:无
内容:1、程序目的:使用外部中断学习计数 这里使用100以内计数,2位数码管
2、硬件要求:数码管、晶振12M
------------------------------------------------*/
#include<reg52.h> //包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义
code unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//共阴数码管 0-9
unsigned char Dis_Shiwei;//定义十位
unsigned char Dis_Gewei; //定义个位
/******************************************************************/
/* 延时函数 */
/******************************************************************/
void delay(unsigned int cnt)
{
while(--cnt);
}
/******************************************************************/
/* 主函数 */
/******************************************************************/
main()
{
EA=1;//全局中断开
EX0=1;//外部中断0开
IT0=1;//边沿触发
while(1)
{
P0=Dis_Shiwei;//显示十位
P2=0;
delay(300); //短暂延时
P0=Dis_Gewei; //显示个位
P2=1;
delay(300);
}
}
/******************************************************************/
/* 外部中断函数 */
/******************************************************************/
void INT0_ISR(void) interrupt 0 using 1
{
static unsigned char second;//定义静态变量,退出该程序后内容不变
second++;//加1
if(second==100)
second=0;
Dis_Shiwei=tab[second/10];//十位显示值处理
Dis_Gewei=tab[second%10]; //个位显示处理
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -