1, the circuit diagram decipher
The circuit board below, is a dedicated programmer control handle lift tables:
Simply look at the circuit board, which is a schematic guess 8 parallel and serial passage, for collecting the pressed key information; two strings turn 8 and drives the three 7-segment:
2, break the principle of its digital display
Thus a simple write a 74HC595 serial write data logic, respectively, to write display data observed (ESP8266 RTOS-based codes transformation from the GPIO DEMO):
#define GPIO_D4 2
#define GPIO_D5 14
#define GPIO_D6 12
#define GPIO_D7 13
#define GPIO_D8 15
#define GPIO_SCK GPIO_D5
#define GPIO_MISO GPIO_D6
#define GPIO_MOSI GPIO_D7
#define GPIO_NSS GPIO_D4
#define GPIO_OUTPUT_PIN_SEL ((1ULL<<GPIO_SCK) | (1ULL<<GPIO_MOSI) | (1ULL<<GPIO_NSS))
#define GPIO_INPUT_PIN_SEL ((1ULL<<GPIO_MISO))
static void gpio_task_example(void *arg)
{
int d = 0xFFDF;//待传输给74HC595的16bits数据
int x = 0;
while (1) {
vTaskDelay(100 / portTICK_RATE_MS);
gpio_set_level(GPIO_MOSI, (d>>x) & 0x01);//数据的一bit
gpio_set_level(GPIO_SCK, 0);//SCK上升沿数据移入
vTaskDelay(1 / portTICK_RATE_MS);
gpio_set_level(GPIO_SCK, 1);
x++;
if(x == 16){//当所有16bits数据都送入了,NSS给一个上升沿,数据送到并口
x=0;
gpio_set_level(GPIO_NSS, 0);
vTaskDelay(1 / portTICK_RATE_MS);
gpio_set_level(GPIO_NSS, 1);
}
}
}
void app_main(void)
{
gpio_config_t io_conf;
//disable interrupt
io_conf.intr_type = GPIO_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
//bit mask of the pins that you want to set,e.g.GPIO15/16
io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
//configure GPIO with the given settings
gpio_config(&io_conf);
//bit mask of the pins, use GPIO4/5 here
io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
//set as input mode
io_conf.mode = GPIO_MODE_INPUT;
//enable pull-up mode
io_conf.pull_up_en = 1;
gpio_config(&io_conf);
//start gpio task
xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL);
while (1) {
vTaskDelay(1000000 / portTICK_RATE_MS);
}
}
74HC595 which the principles of reference: https://blog.csdn.net/weixin_41445387/article/details/80500046
wherein the 3-digit 7-segment like this: [# 2]
3, let the digital display according to their wishes
Thus, the digital code corresponding to 0-9 as follows (16bits data is high 8bits):
digital | coding | Hex |
---|---|---|
0 | 1111 1100 | 0xFC |
1 | 0110 0000 | 0x60 |
2 | 1101 1010 | 0xDA |
3 | 1111 0010 | 0xF2 |
4 | 0110 0110 | 0x66 |
5 | 1011 0110 | 0xB6 |
6 | 1011 1110 | 0xBE |
7 | 1110 0000 | 0xE0 |
8 | 1111 1110 | 0xFE |
9 | 1111 0110 | 0xF6 |
Let the above figures 0-9 by 16bits at different sites in the low byte of the high 3bits implemented:
Place | coding |
---|---|
hundreds | xxxx xxxx 0010 0000 |
Ten | xxxx xxxx 0100 0000 |
Bit | xxxx xxxx 1000 0000 |
If you want to display a 3-digit number, is achieved by rapidly displaying a ten one hundred, the code is implemented as follows:
char digital[10] = {0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6};//0~9
char position[3] = {0x80,0x40,0x20};//百十个
void app_show_digital(int d){//显示1位数字
for(int i=0;i<16;i++){
gpio_set_level(GPIO_MOSI, (d>>i) & 0x01);
gpio_set_level(GPIO_SCK, 0);
gpio_set_level(GPIO_SCK, 1);
}
gpio_set_level(GPIO_NSS, 0);
gpio_set_level(GPIO_NSS, 1);
}
void app_show_num(int num){//分时复用显示3位数字
if(num < 0 || num > 999)return;
static int show_pos = 0;
int gsb[3];//个十百
gsb[0] = digital[num%10];//个
gsb[1] = digital[num/10%10];//十
gsb[2] = digital[num/100];//百
app_show_digital(gsb[show_pos] << 8 | position[show_pos]);
show_pos++;
if(show_pos == 3)show_pos = 0;
}
int show_num = 0;
static void gpio_task_example(void *arg)
{
while (1) {
app_show_num(show_num);
vTaskDelay(9 / portTICK_RATE_MS);
}
}
Note: Here it must be noted, in the make config, the RTOS frequency from 100Hz 200Hz transferred, otherwise the value of 10 or less (10 / portTICK_RATE_MS) vTaskDelay in all treated as 0, and can cause the system watchdog starve restart (watchdog timeout 26.1S also in config)
4, break their logical key operation
简单写一个74HC165串行读数据逻辑,用串口将读取的数据打印下来(代码基于ESP8266 RTOS的GPIO DEMO改造而来):
char app_read_key(void){
char data = 0;
for(int i=0;i<8;i++){
gpio_set_level(GPIO_SCK, 0);
gpio_set_level(GPIO_SCK, 1);
char bit = gpio_get_level(GPIO_MISO) == 0?0:1;
data <<= 1;
data |= bit;
}
return data;
}
int show_num = 0;
static void gpio_task_example(void *arg)
{
while (1) {
app_show_num(show_num);
ESP_LOGI(TAG, "key: %X\n", app_read_key());
vTaskDelay(9 / portTICK_RATE_MS);
}
}
按动不同按键,看读取的数据:
按键 | CODE | 二进制 |
---|---|---|
不按 | 7F | 0111 1111 |
L1 上 | 7D | 0111 1101 |
L2 下 | 7B | 0111 1011 |
L3 一档 | 77 | 0111 0111 |
L4 二档 | 6F | 0110 1111 |
L5 三档 | 5F | 0101 1111 |
L6 四档 | 3F | 0011 1111 |
: 小黑科技:将非智能升降桌改为智能升降桌
: 大家觉得不错,可以点推荐给更多人~
LINKS
[1]. 亮红色共阳0.36英寸3位数码管共阴红光3361AS/BS
[2]. 单片机芯片之——图解74HC595(第一部分)
@beautifulzzzz
以蓝牙技术为基础的的末梢无线网络系统架构及创新型应用探索!
领域:智能硬件、物联网、自动化、前沿软硬件
博客:https://www.cnblogs.com/zjutlitao/
微信交流群|微信:园友交流群|btfzzzz