Não sei como vou 'separar' os dígitos pois a rotina aceita como argumento um Int,mas postando a rotina talvez entenda a sua ideia,lembrando que o modulo usa uma comunicação parecida com I2C.
const char segmentMap[] = {
0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, // 0-7
0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71, // 8-9, A-F
0x00
};
unsigned int Tempo=0;
#include <TM1637.H>
...
void main()
{
...
InitTM1637(2);
Tempo = 200;
tm1637DisplayDecimal(Tempo,1);
...
}
//TM1637.H
#define CLK PIN_A0
#define DIO PIN_A1
void InitTM1637(char brightness);
void start(void);
void ask(void);
void stop(void);
void writeByte(unsigned char oneByte);
void tm1637DisplayDecimal(int v, int displaySeparator);
//
//-----------------------------------------------------------------------------
void InitTM1637(char brightness)
{
start();
writeByte(0x87 + brightness);
ask();
stop();
}
//-----------------------------------------------------------------------------
void start(void)
{
output_high(clk);
output_high(dio);
Delay_us(2);
output_low(dio);
}
//-----------------------------------------------------------------------------
void ask(void)
{
output_low(clk);
Delay_us(5);
// while (dio); // We're cheating here and not actually reading back the response.
output_high(clk);
Delay_us(2);
output_low(clk);
}
//-----------------------------------------------------------------------------
void stop(void)
{
output_low(clk);
Delay_us(2);
output_low(dio);
Delay_us(2);
output_high(clk);
Delay_us(2);
output_high(dio);
}
//-----------------------------------------------------------------------------
void writeByte(unsigned char oneByte)
{
unsigned char i;
for(i=0; i<8; i++)
{
output_low(clk);
if(oneByte & 0x01)
{
output_high(dio);
}
else
{
output_low(dio);
}
Delay_us(3);
oneByte = oneByte >> 1;
output_high(clk);
Delay_us(3);
}
}
//-----------------------------------------------------------------------------
void tm1637DisplayDecimal(int v, int displaySeparator)
{
unsigned char digitArr[4];
for (int i = 0; i < 4; ++i) {
digitArr[i] = segmentMap[v % 10];
if (i == 2 && displaySeparator) {
digitArr[i] |= 1 << 7;
}
v /= 10;
}
start();
writeByte(0x40);
ask();
Stop();
Start();
writeByte(0xc0);
ask();
for (int i = 0; i < 4; ++i) {
writeByte(digitArr[3 - i]);
ask();
}
Stop();
}
O legal da rotina é que voce não precisa preencher os espaço,ela preenche com zeros(0)automaticamente,1=0001.