Electronics > Microcontrollers

Repurpose a Single Use Libero CB temperature logger

<< < (4/4)

DavidAlfa:
Digits test. Probably could be simplified, but it lets you see the mechanics very easily.

--- Code: ---#include <stdbool.h>
#include <stdint.h>

#define char_count 4
#define seg_count 8

#define A   1
#define B   2
#define C   4
#define D   8
#define E   16
#define F   32
#define G   64

const uint8_t digits[] = {
(A+B+C+D+E+F),         //0
(B+C),                 //1
(A+B+G+E+D),           //2
(A+B+C+D+G),           //3
(F+G+B+C),             //4
(A+F+G+C+D),           //5
(A+F+E+D+C+G),         //6
(A+B+C),               //7
(A+B+C+D+E+F+G),       //8
(D+C+B+A+F+G),         //9
};

typedef enum {
seg_a = 0,
seg_b,
seg_c,
seg_d,
seg_e,
seg_f,
seg_g,
seg_dp,
} seg_name_t;

typedef enum {
char_1 = 0,
char_2,
char_3,
char_4,
} char_name_t;

typedef struct{
const uint8_t reg;
} seg_data_t;

seg_data_t seg_data[char_count][seg_count] = {
[char_1] = {
[seg_a]   = { LCD_RAM_REGISTER0, 1  },
[seg_b]   = { LCD_RAM_REGISTER0, 5  },
[seg_c]   = { LCD_RAM_REGISTER4, 5  },
[seg_d]   = { LCD_RAM_REGISTER6, 1  },
[seg_e]   = { LCD_RAM_REGISTER4, 1  },
[seg_f]   = { LCD_RAM_REGISTER2, 1  },
[seg_g]   = { LCD_RAM_REGISTER2, 5  },
},
[char_2] = {
[seg_a]   = { LCD_RAM_REGISTER0, 6  },
[seg_b]   = { LCD_RAM_REGISTER0, 10 },
[seg_c]   = { LCD_RAM_REGISTER4, 10 },
[seg_d]   = { LCD_RAM_REGISTER6, 6  },
[seg_e]   = { LCD_RAM_REGISTER4, 6  },
[seg_f]   = { LCD_RAM_REGISTER2, 6  },
[seg_g]   = { LCD_RAM_REGISTER2, 10 },
[seg_dp]  = { LCD_RAM_REGISTER6, 10 },
},
[char_3] = {
[seg_a]   = { LCD_RAM_REGISTER0, 11 },
[seg_b]   = { LCD_RAM_REGISTER0, 12 },
[seg_c]   = { LCD_RAM_REGISTER4, 12 },
[seg_d]   = { LCD_RAM_REGISTER6, 11 },
[seg_e]   = { LCD_RAM_REGISTER4, 11 },
[seg_f]   = { LCD_RAM_REGISTER2, 11 },
[seg_g]   = { LCD_RAM_REGISTER2, 12 },
[seg_dp]  = { LCD_RAM_REGISTER6, 12 },
},
[char_4] = {
[seg_a]   = { LCD_RAM_REGISTER0, 13 },
[seg_b]   = { LCD_RAM_REGISTER0, 14 },
[seg_c]   = { LCD_RAM_REGISTER4, 14 },
[seg_d]   = { LCD_RAM_REGISTER6, 13 },
[seg_e]   = { LCD_RAM_REGISTER4, 13 },
[seg_f]   = { LCD_RAM_REGISTER2, 13 },
[seg_g]   = { LCD_RAM_REGISTER2, 14 },
},
};

void clear_char(char_name_t c){

for(uint8_t i=0; i<seg_count; i++){
}
HAL_LCD_UpdateDisplayRequest(&hlcd);
}

// Dp not implemented
void write_char(char_name_t c, uint8_t number, bool dp){

if (number>9)
number=8;

for(uint8_t i=0; i<seg_count; i++){
( ((1<<i) & digits[number]) ? mask : 0 ) );
}
HAL_LCD_UpdateDisplayRequest(&hlcd);
}

void main(void){
uint8_t a=0, b=0, c=0, d=0;

while(1){
write_char(char_1, a, false);
write_char(char_2, b, false);
write_char(char_3, c, false);
write_char(char_4, d, false);

if(++a>9){
a=0;
if(++b>9){
b=0;
if(++c>9){
c=0;
if(++d>9)
d=0;
}
}
}
HAL_Delay(1000);
}
}

--- End code ---