用vue搭建一个登录页面
时间: 2024-05-08 07:18:03 浏览: 46
Vue登录页面
以下是硬件设计和软件编程实现的示例代码:
硬件设计:
```
// P2口接矩阵键盘
sbit COL1 = P2^0;
sbit COL2 = P2^1;
sbit COL3 = P2^2;
sbit ROW1 = P2^3;
sbit ROW2 = P2^4;
sbit ROW3 = P2^5;
sbit ROW4 = P2^6;
// P1口和P3口接两个数码管
sbit DIG1 = P1^0;
sbit DIG2 = P1^1;
sbit A = P1^2;
sbit B = P1^3;
sbit C = P1^4;
sbit D = P1^5;
sbit E = P1^6;
sbit F = P1^7;
sbit DIG3 = P3^0;
sbit DIG4 = P3^1;
sbit G = P3^2;
sbit DP = P3^3;
sbit D1 = P3^4;
sbit D2 = P3^5;
sbit D3 = P3^6;
sbit D4 = P3^7;
```
软件编程实现:
```
#include <reg52.h>
// 定义数码管显示的字符
unsigned char code LEDChar[] = {
0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x00, 0x40
};
// 定义按键值
unsigned char code KeyVal[] = {
1, 2, 3, 0x0A,
4, 5, 6, 0x0B,
7, 8, 9, 0x0C,
0, 0x0F, 0, 0x0E
};
// 定义变量
unsigned char keyValue = 0; // 按键值
unsigned char digit1 = 0; // 数码管1显示的数字
unsigned char digit2 = 0; // 数码管2显示的数字
unsigned char isLooping = 0; // 是否在循环显示状态
// 延时函数
void delay(unsigned int time) {
while (time--);
}
// 扫描矩阵键盘,返回按下的键值
unsigned char scanKey() {
unsigned char i, j;
unsigned char key = 0;
COL1 = 0;
COL2 = 1;
COL3 = 1;
if (ROW1 == 0) {
delay(1000); // 延时去抖
if (ROW1 == 0) {
key = KeyVal[0];
}
} else if (ROW2 == 0) {
delay(1000);
if (ROW2 == 0) {
key = KeyVal[1];
}
} else if (ROW3 == 0) {
delay(1000);
if (ROW3 == 0) {
key = KeyVal[2];
}
} else if (ROW4 == 0) {
delay(1000);
if (ROW4 == 0) {
key = KeyVal[3];
}
}
COL1 = 1;
COL2 = 0;
COL3 = 1;
if (ROW1 == 0) {
delay(1000);
if (ROW1 == 0) {
key = KeyVal[4];
}
} else if (ROW2 == 0) {
delay(1000);
if (ROW2 == 0) {
key = KeyVal[5];
}
} else if (ROW3 == 0) {
delay(1000);
if (ROW3 == 0) {
key = KeyVal[6];
}
} else if (ROW4 == 0) {
delay(1000);
if (ROW4 == 0) {
key = KeyVal[7];
}
}
COL1 = 1;
COL2 = 1;
COL3 = 0;
if (ROW1 == 0) {
delay(1000);
if (ROW1 == 0) {
key = KeyVal[8];
}
} else if (ROW2 == 0) {
delay(1000);
if (ROW2 == 0) {
key = KeyVal[9];
}
} else if (ROW3 == 0) {
delay(1000);
if (ROW3 == 0) {
key = KeyVal[10];
}
} else if (ROW4 == 0) {
delay(1000);
if (ROW4 == 0) {
key = KeyVal[11];
}
}
COL1 = 1;
COL2 = 1;
COL3 = 1;
return key;
}
// 数码管动态显示
void display(unsigned char digit, unsigned char value) {
// 显示位选
switch (digit) {
case 1:
DIG1 = 0;
DIG2 = 1;
break;
case 2:
DIG1 = 1;
DIG2 = 0;
break;
case 3:
DIG3 = 0;
DIG4 = 1;
break;
case 4:
DIG3 = 1;
DIG4 = 0;
break;
}
// 显示数码
A = LEDChar[value] & 0x01;
B = LEDChar[value] & 0x02;
C = LEDChar[value] & 0x04;
D = LEDChar[value] & 0x08;
E = LEDChar[value] & 0x10;
F = LEDChar[value] & 0x20;
G = LEDChar[value] & 0x40;
}
// 主函数
void main() {
while (1) {
if (!isLooping) {
// 非循环状态
keyValue = scanKey();
if (keyValue) {
// 有按键按下
if (keyValue == 0x0E) {
// 按下两个9,进入循环状态
digit1 = 0;
digit2 = 1;
isLooping = 1;
} else {
// 显示按下的键值
digit1 = keyValue / 10;
digit2 = keyValue % 10;
}
}
} else {
// 循环状态
digit1++;
digit2++;
if (digit1 == 2 && digit2 == 0) {
digit1 = 0;
digit2 = 1;
}
if (digit1 == 1 && digit2 == 1) {
// 按下两次1,退出循环状态
isLooping = 0;
}
}
display(1, digit1);
display(2, digit2);
delay(1000);
}
}
```
阅读全文