📄 key.c
字号:
#include <reg51.h>
#include <stdio.h>
#define uchar unsigned char
unsigned char key_scan(void );
void send(uchar add,uchar );
void s_seg(uchar,uchar ,uchar,uchar,uchar,uchar,uchar , uchar);
uchar vo[]; // 输入速度存储区
uchar length[]; // 输入间距存储区
bit enterflag; // 确认键按下与否标志
void delay(void) //延时函数
{
uchar i;
for (i=300;i>0;i--);
}
uchar Peyscan(void) //键盘扫描函数
{
uchar scan,tep;
P1=0xf0; // 发全0扫描码
if((P1&0xf0)==0xf0) //若有键盘按下
{
delay(); //延时函数
if((P1&0xf0)==0xf0) //再判断一次,去除抖动
{
scan=0xfe;
while((scan&0x10)!=0) // 顺行扫描
{
P1=scan; //输出行扫描码
if((P1&0xf0)!=0xf0) //本行有键按下
{
tep = (P1&0xf0)|0x0f;
return((~scan)+(~tep));
}
else scan=(scan<<1)|0x01; //行扫描码左移一位
}
}
} //无键按下,返回值0
return(0);
}
uchar getcode(uchar i)
{
uchar P;
switch(i)
{
case 0: /* 0 */
P=0x3f;
break;
case 1: /* 1 */
P=0x06;
break;
case 2: /* 2 */
P=0x5B;
break;
case 3: /* 3 */
P=0x4f;
break;
case 4:
P=0x66; /* 4 */
break;
case 5:
P=0x6D; /* 5 */
break;
case 6:
P=0x7D; /* 6 */
break;
case 7: /* 7 */
P=0x07;
break;
case 8: /* 8 */
P=0x7F;
break;
case 9: /* 9 */
P=0x67;
break;
case 10: /* A */
P=0x77;
break;
case 11: /* B */
P=0x7c;
break;
case 12: /* C */
P=0x39;
break;
case 13: /* D */
P=0x5E;
break;
case 14: /* E */
P=0x79;
break;
case 15: /* F */
P=0x71;
break;
default:
break;
}
return(P);
}
P1 = 0xf0; // 发全0扫描码
while((P1&0xf0)!=0xf0)
//若没松开按键
{
P1 = 0xf0;
}
/* 主电机转动 */
int x
unsigned char output[6] ={0x08,0x24,0x16,0x48,0x32,0x40}
unsigned i=0
while x>0
{
P1=output[i] ;
Delay();
i++;
if(i==6) i=0;
}
/* 排电机转动 */
void send(uchar add,uchar dat)
{
uchar ADS,i,j;
CLP=0;
LOAD=0;
DIN=0;
i=4;
while(i<16)
{
if(i<8)
{
ADS=add;
}
else
{
ADS=dat;
}
for(j=8;j>=1;j--)
{
if((ADS&0x80)==0)
{ DIN=0 ;}
else
{ DIN=1;}
ADS=ADS<<1;
CLP=1;
CLP=0;
}
i=i+8;
}
LOAD=1;
}
void s_seg(uchar X1,uchar X2,uchar X3,uchar X4,uchar X5,uchar X6,uchar X7, uchar X8)
{
send(0x0c,0x01);//正常状态
send(0x0b,0x07);//设置扫描范围DIG0-7
send(0x0a,0x05);//设置亮度11/32
send(0x09,0xff);//采用译码方式
send(0x01,X1);
send(0x02,X2);
send(0x03,X3);
send(0x04,X4);
send(0x05,X5);
send(0x06,X6);
send(0x07,X7);
send(0x08,X8);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -