本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
H文件:
#ifndef _DIY_H_
#define _DIY_H_
typedef unsigned char uint8;
typedef unsigned int uint16;
#define PORT0 P0
#define PORT1 P1
#define PORT2 P2
#define PORT3 P3
#endif
主程序:
#include<reg52.h>
#include"diy.h"
#define key_state1 1
#define key_state2 2
#define key_state3 3
unsigned char const dofly[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
0x77,0x7c,0x39,0x5e,0x79,0x71};//0-F
void Key_Scan()
{
uint8 value_l,value_r,key_value,table;
static uint8 key_state=1;
switch(key_state)
{
case key_state1:
PORT3=0XF0;
value_l=PORT3&0XF0;
if(value_l!=0XF0)
{
key_state=key_state2;
value_l=PORT3&0Xf0;
PORT3=0X0F;
value_r=PORT3&0x0f;
key_value=(value_l|value_r);
}
else
{key_state=key_state1;}
break;
case key_state2:
{
switch(key_value)
{
case 0x7e: table=dofly[0];key_state=2;break;
case 0x7d: table=dofly[1];key_state=2;break;
case 0x7b: table=dofly[2];key_state=2;break;
case 0x77: table=dofly[3];key_state=2;break;
case 0xbe: table=dofly[4];key_state=2;break;
case 0xbd: table=dofly[5];key_state=2;break;
case 0xbb: table=dofly[6];key_state=2;break;
case 0xb7: table=dofly[7];key_state=2;break;
case 0xde: table=dofly[8];key_state=2;break;
case 0xdd: table=dofly[9];key_state=2;break;
case 0xdb: table=dofly[10];key_state=2;break;
case 0xd7: table=dofly[11];key_state=2;break;
case 0xee: table=dofly[12];key_state=2;break;
case 0xed: table=dofly[13];key_state=2;break;
case 0xeb: table=dofly[14];key_state=2;break;
case 0xe7: table=dofly[15];key_state=2;break;
default :key_state=key_state1;break;
}
}
break;
case key_state3:
if(value_l!=0XF0)
while(value_l!=0XF0)
{
PORT2=0x00;
PORT0=dofly |