Skip to main content
added 126 characters in body
Source Link
Oli Glaser
  • 55.5k
  • 3
  • 77
  • 148
void load_data(char seg1, char seg2, char seg3)
{
    char i, temp;
    char position = 0;

    set_data_pin(1);  // clock start bit in
    set_clock_pin(1);
    delay_us(5);
    set_clock_pin(0);
    delay_us(5);

    temp = seg1;
    while(i<8)
    {
        set_data_pin(temp & 0x80);  // set data pin
        set_clock_pin(1);
        delay_us(5);
        set_clock_pin(0);
        delay_us(5);
        i++;
        temp = temp << i; // shift next bit out
    }
    
    temp = seg2;
    while(i<8)
    {
        set_data_pin(temp & 0x80);  // set data pin
        set_clock_pin(1);
        delay_us(5);
        set_clock_pin(0);
        delay_us(5);
        i++;
        temp = temp << i; // shift next bit out
    }
 
    temp = seg3;
    while(i<8)
    {
        set_data_pin(temp & 0x80);  // set data pin
        set_clock_pin(1);
        delay_us(5);
        set_clock_pin(0);
        delay_us(5);
        i++;
        temp = temp << i; // shift next bit out
    }

    // Last 11 bits - do something here if needed
    while(i<11)
    {
        set_data_pin(0);  // set data pin
        set_clock_pin(1);
        delay_us(5);
        set_clock_pin(0);
        delay_us(5);
        i++;
    }
}
void load_data(char seg1, char seg2, char seg3)
{
    char i, temp;
    char position = 0;

    set_data_pin(1);  // clock start bit in
    set_clock_pin(1);
    delay_us(5);
    set_clock_pin(0);

    temp = seg1;
    while(i<8)
    {
        set_data_pin(temp & 0x80);  // set data pin
        set_clock_pin(1);
        delay_us(5);
        set_clock_pin(0);
        i++;
        temp = temp << i; // shift next bit out
    }
    
    temp = seg2;
    while(i<8)
    {
        set_data_pin(temp & 0x80);  // set data pin
        set_clock_pin(1);
        delay_us(5);
        set_clock_pin(0);
        i++;
        temp = temp << i; // shift next bit out
    }
 
    temp = seg3;
    while(i<8)
    {
        set_data_pin(temp & 0x80);  // set data pin
        set_clock_pin(1);
        delay_us(5);
        set_clock_pin(0);
        i++;
        temp = temp << i; // shift next bit out
    }

    // Last 11 bits - do something here if needed
    while(i<11)
    {
        set_data_pin(0);  // set data pin
        set_clock_pin(1);
        delay_us(5);
        set_clock_pin(0);
        i++;
    }
}
void load_data(char seg1, char seg2, char seg3)
{
    char i, temp;
    char position = 0;

    set_data_pin(1);  // clock start bit in
    set_clock_pin(1);
    delay_us(5);
    set_clock_pin(0);
    delay_us(5);

    temp = seg1;
    while(i<8)
    {
        set_data_pin(temp & 0x80);  // set data pin
        set_clock_pin(1);
        delay_us(5);
        set_clock_pin(0);
        delay_us(5);
        i++;
        temp = temp << i; // shift next bit out
    }
    
    temp = seg2;
    while(i<8)
    {
        set_data_pin(temp & 0x80);  // set data pin
        set_clock_pin(1);
        delay_us(5);
        set_clock_pin(0);
        delay_us(5);
        i++;
        temp = temp << i; // shift next bit out
    }
 
    temp = seg3;
    while(i<8)
    {
        set_data_pin(temp & 0x80);  // set data pin
        set_clock_pin(1);
        delay_us(5);
        set_clock_pin(0);
        delay_us(5);
        i++;
        temp = temp << i; // shift next bit out
    }

    // Last 11 bits - do something here if needed
    while(i<11)
    {
        set_data_pin(0);  // set data pin
        set_clock_pin(1);
        delay_us(5);
        set_clock_pin(0);
        delay_us(5);
        i++;
    }
}
added 607 characters in body
Source Link
Oli Glaser
  • 55.5k
  • 3
  • 77
  • 148

Note that the datasheet is not particularly helpful with details on the brightness control pin - it shows the pot set up for a varying voltage control in the diagram which confuses things a bit. I have just ignored this diagram and taken what is written to be correct. I'm also assuming the resistance to be across the full 5V (i.e. the BC pin is just above 0V), which is probably not be the case, but it's better to be on the conservative side if no details are given.
This means you may need to experiment a bit to get the brightness right - if it's too dim try changing to a lower resistance.

Note that the datasheet is not particularly helpful with details on the brightness control pin - it shows the pot set up for a varying voltage control in the diagram which confuses things a bit. I have just ignored this diagram and taken what is written to be correct. I'm also assuming the resistance to be across the full 5V (i.e. the BC pin is just above 0V), which is probably not be the case, but it's better to be on the conservative side if no details are given.
This means you may need to experiment a bit to get the brightness right - if it's too dim try changing to a lower resistance.

added 1545 characters in body
Source Link
Oli Glaser
  • 55.5k
  • 3
  • 77
  • 148
 \$  \dfrac{+5V}{20mA / 36} = 9k\Omega \$\$  \dfrac{+5V}{20mA \div 36} = 9k\Omega \$   

This is the minimum value of resistance we would use (connected between +5V and BC pin)
If we want to vary the current, say from \$10mA - 20mA\$, then we can add a \$250\Omega\$\$9k\Omega\$ pot in series with the resistor with it's wiper connected to one end (either end) Then the current varies between:

\$ \dfrac{+5V}{250\Omega} = 20mA \$\$ \dfrac{+5V}{9k\Omega} \times 36 = 20mA \$

\$ \dfrac{+5V}{250\Omega + 250\Omega} = 10mA \$\$ \dfrac{+5V}{9k\Omega + 9k\Omega} \times 36 = 10mA \$

 \$  \dfrac{+5V}{20mA / 36} = 9k\Omega \$   

This is the minimum value of resistance we would use (connected between +5V and BC pin)
If we want to vary the current, say from \$10mA - 20mA\$, then we can add a \$250\Omega\$ pot in series with the resistor with it's wiper connected to one end (either end) Then the current varies between:

\$ \dfrac{+5V}{250\Omega} = 20mA \$

\$ \dfrac{+5V}{250\Omega + 250\Omega} = 10mA \$

 \$  \dfrac{+5V}{20mA \div 36} = 9k\Omega \$   

This is the minimum value of resistance we would use (connected between +5V and BC pin)
If we want to vary the current, say from \$10mA - 20mA\$, then we can add a \$9k\Omega\$ pot in series with the resistor with it's wiper connected to one end (either end) Then the current varies between:

\$ \dfrac{+5V}{9k\Omega} \times 36 = 20mA \$

\$ \dfrac{+5V}{9k\Omega + 9k\Omega} \times 36 = 10mA \$

added 1545 characters in body
Source Link
Oli Glaser
  • 55.5k
  • 3
  • 77
  • 148
Loading
Source Link
Oli Glaser
  • 55.5k
  • 3
  • 77
  • 148
Loading