text1.c

来自「基于AT89C51系列单片机的按键识别的C51程序按键中断识别.rar」· C语言 代码 · 共 57 行

C
57
字号
#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 + =
减小字号Ctrl + -
显示快捷键?