⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 display_ok.c

📁 用于4*4键盘扫描程序
💻 C
字号:
//4*4键盘扫描和显示C程序
#include<reg51.h> 
//以上为端口定义头文件
sbit JDQ = P3 ^ 0;
//===================================================
//定时器T0情况
#define count_M1 50000
#define TH_M1 (65536-count_M1)/256
#define TL_M1 (65536-count_M1)%256
int count_T0 = 0;
//定时器T1情况
#define count_M2 250
#define TH_M2 (256-count_M2)
#define TL_M2 (256-count_M2)
int count_T1 = 0;
char wich;
//====================================================

char disp [4] = {0x7f, 0x7f, 0x7f, 0x7f};
char seconds, minutes, total=10;
//    total=80;
void main()
{
	IE = 0X8A;
	TMOD = 0X21;
	TH0 = TH_M1;TL0 = TL_M1;
	TH1 = TH_M2;TL1 = TL_M2;
	TR0 = 1;
	TR1 = 1;
	while (1);
}
//------------------------------------------------------------------------------

void T0_1s(void)interrupt 1
{

	TH0 = TH_M1;TL0 = TL_M1;
	if (++count_T0 == 20)
	{
	count_T0 = 0;
	total--;
	if (total == 0)
	{
	        total=10;
			JDQ = 0;
	}
	}
	minutes = total / 60;
	seconds = total % 60;
	disp[3] = seconds % 10;
	disp[2] = seconds / 10;
	disp[1] = minutes % 10;
	disp[0] = minutes / 10;
}
void T1_4ms(void)interrupt 3
{
char old_dis=0x01;
	if ( ++ count_T1 == 64)
	{
	count_T1 = 0;
	if (++ wich == 5) wich = 1;
		P0 = 0xff;
		P2 = ~(old_dis<<(wich-1));
		P0 = disp[wich - 1];
	}
}

⌨️ 快捷键说明

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