serviceimpl save方法返回的boolean值是什么
时间: 2024-05-12 11:21:07 浏览: 63
本题需要使用按键和数码管,因此需要先定义引脚。
```c
sbit KEY1 = P3^2;
sbit KEY2 = P3^3;
sbit KEY3 = P3^4;
sbit KEY4 = P3^5;
sbit LED = P0;
```
然后定义一个字符数组,存储要显示的字符。
```c
unsigned char letter[4][8] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //空字符
{0x3F,0x48,0x48,0x48,0x3F,0x00,0x00,0x00}, //字母A
{0x3F,0x21,0x21,0x21,0x1E,0x00,0x00,0x00}, //字母B
{0x1E,0x21,0x21,0x21,0x12,0x00,0x00,0x00}, //字母C
{0x3F,0x21,0x21,0x21,0x1E,0x00,0x00,0x00}, //字母D
};
```
接着是数码管显示函数,根据动态显示的原理,每个数码管只能显示一个字符,需要控制显示的时间和显示的位置。
```c
void display(unsigned char *p) //p为要显示的字符指针
{
unsigned char i, j;
for(i=0; i<8; i++) //8列循环
{
for(j=0; j<4; j++) //4行循环
{
LED = 0xFF; //关闭所有数码管
P2 = 0x01<<j; //选择要显示的数码管
P1 = ~*(p+i*4+j); //显示对应的字符
delay(1); //延时
}
}
}
```
最后是主函数,需要轮询按键状态,根据按键状态选择要显示的字符。
```c
void main()
{
unsigned char key;
while(1)
{
if(KEY1==0) //按键1按下
key = 1;
else if(KEY2==0) //按键2按下
key = 2;
else if(KEY3==0) //按键3按下
key = 3;
else if(KEY4==0) //按键4按下
key = 4;
else
continue;
display(&letter[key][0]); //显示对应的字符
}
}
```
完整代码如下:
```c
#include <reg52.h>
sbit KEY1 = P3^2;
sbit KEY2 = P3^3;
sbit KEY3 = P3^4;
sbit KEY4 = P3^5;
sbit LED = P0;
void delay(unsigned int t)
{
while(t--);
}
unsigned char letter[4][8] = {
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //空字符
{0x3F,0x48,0x48,0x48,0x3F,0x00,0x00,0x00}, //字母A
{0x3F,0x21,0x21,0x21,0x1E,0x00,0x00,0x00}, //字母B
{0x1E,0x21,0x21,0x21,0x12,0x00,0x00,0x00}, //字母C
{0x3F,0x21,0x21,0x21,0x1E,0x00,0x00,0x00}, //字母D
};
void display(unsigned char *p)
{
unsigned char i, j;
for(i=0; i<8; i++)
{
for(j=0; j<4; j++)
{
LED = 0xFF;
P2 = 0x01<<j;
P1 = ~*(p+i*4+j);
delay(1);
}
}
}
void main()
{
unsigned char key;
while(1)
{
if(KEY1==0)
key = 1;
else if(KEY2==0)
key = 2;
else if(KEY3==0)
key = 3;
else if(KEY4==0)
key = 4;
else
continue;
display(&letter[key][0]);
}
}
```
阅读全文