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

📄 7289.c

📁 这是一个ZLG7289的读键盘程序
💻 C
字号:
#include "reg52.h"

sbit KEY = P3^3;
sbit CS = P3^1;
sbit CLK = P3^0;
sbit DIO= P3^2;

void DisPlay(KeyValue, char all);

void Delay(int  time)
{
	do
	{
		int j;
		for(j=0; j<5; j++)
			;
	} while (--time);
}

/*发送指令或数据到7289*/
void SendCmd(unsigned char cmd)
{
	unsigned char BitCnt = 8;
	CS = 0;
	Delay(50);

	while(BitCnt--)
	{
		DIO = cmd >> 7;
		cmd<<=1;
		CLK = 1;
		Delay(10);
		CLK = 0;
		Delay(10);
	}
	DIO = 0;

}

/*接受Key值从7289*/
 unsigned char Receive()
{
	unsigned char BitCnt = 8;
	unsigned char  rec = 0;
	DIO = 1;
	CS = 0;
	Delay(50);
	while(BitCnt--)
	{
		CLK = 1;
		Delay(10);
		rec= (rec<<1)|DIO;
		CLK=0;
		Delay(10);
	}
	DIO = 0;
	return rec;

}

/*等待Key按下,如果按下,接受Key值*/
unsigned char  FindKey(NewKey)
{
	unsigned char KeyValue;
	KEY = 1;
	Delay(50);
	while(KEY)
        {
           ;
	}
	SendCmd(0x15);
	KeyValue = Receive();
	CS=1;
	return KeyValue	;
}

/*如果all=1, 8个数码 管一起显示KeyValue,否则根据位数显示*/
void DisPlay(KeyValue, char all)
{
	 unsigned char  LedValue;

	 unsigned char  ledsel = 0x87;
	 int i;
	 if(!all)
	  	SendCmd(0xA4);
	 for(i=0; i<8;i++)
	 {
		 LedValue = KeyValue%10;
		 SendCmd(ledsel-i);
		 SendCmd(LedValue);
		 CS = 1;
		 KeyValue/=10;
		 if((!all) && (KeyValue ==0))
			 break;
	 }

}

/*on=1 Led	闪,否则on=0,不闪*/
void LedShine(int  on)
{
	 SendCmd(0x88);
	 if(on)
	 	SendCmd(0x0);
	 else
	 	SendCmd(0xff);
	 CS = 1;
}

/*Led左移一位*/
void  LedLsl()
{
	 SendCmd(0xA0);
	 CS = 1;
}



void main(void)
{   unsigned char KeyValue,NewKey;
    int i;
    CS = 1;
	KEY = 1;
	DIO = 1;
	Delay(10);
	SendCmd(0xA4);
	Delay(10);
    DisPlay(0, 1);
 	Delay(5000);
 	DisPlay(8, 0);

 	for(i=0; i<8; i++)
 	{
 	 Delay(3000);
 	 LedLsl();
 	}
        while(1)
       {
        KeyValue = FindKey(NewKey);
        DisPlay(KeyValue,0);
       }
	


}

⌨️ 快捷键说明

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