counter3_1.c

来自「//00-99按键计数器每按一次加一显示 //软件延时 //已经测试」· C语言 代码 · 共 72 行

C
72
字号
//00-99按键计数器每按一次加一显示
//软件延时
//已经测试
#include<reg51.h>
#define uchar unsigned char
sbit T138_A=P1^0;
sbit T138_B=P1^1;
sbit T138_C=P1^2;
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
uchar count,temp,num;
void Display(uchar num);
void IO_int()
{	
	count=0;
	temp=0;
}
void Delay(uchar i)
{
	unsigned int j;
	for(;i>0;i--)
	{
		for(j=0;j<110;j++);
	}
}
void main()
{
	IO_int();
	while(1)
	{
	P0=0xfe;
	temp=P0;
	Delay(50);
	temp=P0;
	temp=temp&0xf0;
	if(temp!=0xf0)
	{
		Delay(20);
		temp=P0;
		temp=temp&0xf0;
		if(temp!=0xf0)
		{	
			switch(temp)
			{
				case 0xe0:count++;
			}
		}
	}
		 if(count>59)
		 {
		 count=0;
		 }
		 Display(count);
	}
}
void Display(uchar num)
{
	unsigned int shi,ge;
	shi=num/10;
	ge=num%10;
	T138_A=0;
	T138_B=1;
	T138_C=0;
	P2=table[shi];
	Delay(30);
	P2=0;
	T138_A=1;
	T138_B=1;
	T138_C=0;
	P2=table[ge];
	Delay(10);
	P2=0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?