Serial LED displays

Discussion in 'The Projects Forum' started by takao21203, Feb 18, 2013.

  1. takao21203

    Thread Starter AAC Fanatic!

    Apr 28, 2012
    They are ready to use now, nearly two years after the PCBs were made.

    XC8 is used now both for the displays, and to send the serial data.

    Since a 16f54 is used, each time the data is sent, the display goes off for 20 msecs. This is because of the DRT (Device reset timer).

    A 16f716 could be used which is pin compatible.

    The code to send the serial data is shown.
    It is also possible to use the hardware serial port!
    However, 20 milliseconds delay is neccessary each time as long as 16f54 is used.

    Having the displays available now means a simplification for many circuits. Never to wire 7seg. displays again!

    I made it working using assembler, but it was so complicated, I did not want to use them myself. As well, external components were neccessary. Not anymore! Only 3 wires are required.

    Code ( (Unknown Language)):
    2. #include <xc.h>         /* XC8 General Include File */
    4. #include "system.h"        /* System funct/params, like osc/peripheral config */
    5. #include "user.h"          /* User funct/params, such as InitApp */
    7. #define clk LATAbits.LATA0
    8. #define dat LATAbits.LATA1
    9. #define reset LATCbits.LATC1
    10. #define delay 0
    12. unsigned int tmr0;
    14. void send_ser(unsigned char ser_dat)
    15. {unsigned char i;
    17. if(ser_dat&0x01)dat=1; else dat=0;
    18. clk=1;i=delay;while(i--);clk=0;
    20. if(ser_dat&0x02)dat=1; else dat=0;
    21. clk=1;i=delay;while(i--);clk=0;
    23. if(ser_dat&0x04)dat=1; else dat=0;
    24. clk=1;i=delay;while(i--);clk=0;
    26. if(ser_dat&0x08)dat=1; else dat=0;
    27. clk=1;i=delay;while(i--);clk=0;
    29. if(ser_dat&0x10)dat=1; else dat=0;
    30. clk=1;i=delay;while(i--);clk=0;
    32. }
    34. void init_ser()
    35. {unsigned int i;
    36.   clk=0;
    37.   dat=0;
    38.   reset=0;
    39.   reset=1;
    40.   i=200;while(i--);
    41. }
    43. void interrupt isr(void)
    44. {
    45.     if(TMR0IF)
    46.     {
    47.     TMR0IF=0; /* Clear Interrupt Flag 1 */
    49.     tmr0++;
    50.     if(tmr0>20)
    51.     {
    52.      LATC=0;
    53.      LATA=0;
    54.      TRISA=0b11111100;
    55.      TRISC=0b11110101;
    56.      tmr0=0;
    57.      init_ser();
    58.      send_ser(1);
    59.      send_ser(2);
    60.      send_ser(3);
    61.      send_ser(4);
    63.      TRISA=0xff;
    64.      TRISC=0b11110111;
    65.     }}
    66. }
    68.     void main(void)
    69. {
    71.     InitApp();
    73.     GIE=1;
    74.     TMR0IE=1;
    76.     while(1){}
    78. }
    Note the display PCB is on the bottom of the LED 7seg module. The green PCB is only used for testing (16f1503).

    The switches are neccessary for FLASH programming since the header is shared, as well the pins are used to transmit the serial data. Later in a real circuit, no switches are needed.

    The displays will be available soon for sale. Time to make a profit of $1 or $2 after years and spending 1000s on components.
  2. takao21203

    Thread Starter AAC Fanatic!

    Apr 28, 2012
    The code for the displays as well.

    Code ( (Unknown Language)):
    1. #include <xc.h>         /* XC8 General Include File */
    2. #include "system.h"      
    3. #include "user.h"          /* User funct/params, such as InitApp */
    5. const unsigned char ph_PORTA[]={2,2,0,2};
    6. const unsigned char ph_PORTB[]={0x81,0x41,0xc1,0xc0};
    8. const unsigned char dig_PORTA[]={0xd,0x1,0x9,0x9,0x5,0xc,0xc,0x9,\
    9.                                  0xd,0xd,0xd,0x4,0xc,0x1,0xc,0xc,\
    10.                                  0x0,0x5,0x4};
    12. const unsigned char dig_PORTB[]={0x16,0x10,0x26,0x34,\
    13.                                  0x30,0x34,0x36,0x30,\
    14.                                  0x36,0x34,0x32,0x36,\
    15.                                  0x06,0x36,0x26,0x22,\
    16.                                  0x20,0x32,0x06};
    18. unsigned char v_digit0,v_digit1,v_digit2,v_digit3;
    19. unsigned char v_phase,v_refresh,v_PORTA,v_PORTB;
    20. unsigned char v_digit_data;
    22. #define clk PORTBbits.RB7
    23. #define data PORTBbits.RB6
    25. void get_serial()
    26. {
    27.     v_digit_data=0;
    28.     while(!clk);if(data)v_digit_data|=1;
    29.     while(clk);
    30.     while(!clk);if(data)v_digit_data|=2;
    31.     while(clk);
    32.     while(!clk);if(data)v_digit_data|=4;
    33.     while(clk);
    34.     while(!clk);if(data)v_digit_data|=8;
    35.     while(clk);
    36.     while(!clk);if(data)v_digit_data|=10;
    37.     while(clk);
    38. }
    39. void main(void)
    40. {
    41.     TRISA= 0xff;
    42.     TRISB= 0xff;
    43.     v_phase=0;
    44.     v_refresh=0;
    46.     get_serial();
    47.     v_digit0=v_digit_data&0x0f;
    48.     get_serial();
    49.     v_digit1=v_digit_data&0xf;
    50.     get_serial();
    51.     v_digit2=v_digit_data&0xf;
    52.     get_serial();
    53.     v_digit3=v_digit_data&0xf;
    55.     /* Initialize I/O and Peripherals for application */
    56.     PORTA=0;
    57.     PORTB=0;
    58.     TRISB=0;TRISA=0;
    59.     OPTION=4;
    61.     while(1)
    62.     {
    63.         if((TMR0>0x80)&&(v_refresh==0))
    64.         {
    65.          v_refresh=0x77;
    66.          if(v_phase==0)v_digit_data=v_digit0;
    67.          if(v_phase==1)v_digit_data=v_digit1;
    68.          if(v_phase==2)v_digit_data=v_digit2;
    69.          if(v_phase==3)v_digit_data=v_digit3;
    70.          v_PORTA=ph_PORTA[v_phase]|dig_PORTA[v_digit_data];
    71.          v_PORTB=ph_PORTB[v_phase]|dig_PORTB[v_digit_data];
    72.          PORTA=v_PORTA;PORTB=v_PORTB;
    73.          v_phase++;if(v_phase==4)v_phase=0;
    74.         }else v_refresh=0x00;
    75.     }
    77. }
    Since it is not really sophisticated technology, and I wrote it in an hour.

    However you need to build a new data table for each different display, and also the data table depends on the PCB layout.

    It is only shown to give you an idea.

    It does not just work on any display or PCB.

    For the schematic, well all display pins are connected to PIC I/O bits. The serial port is on RB6/RB7.
  3. takao21203

    Thread Starter AAC Fanatic!

    Apr 28, 2012
  4. Markd77

    Senior Member

    Sep 7, 2009
    You could poll the serial pins in the display loop and avoid the extra wire needed for reset. You might have to reduce the rate the serial data is sent, but as it would also get rid of the 20ms device reset timer it would probably be faster overall.
    You could do the same but with asynchronous serial and then only one pin would be required.
  5. takao21203

    Thread Starter AAC Fanatic!

    Apr 28, 2012
    yes I have done it that way before- resulting in a lengthy source code.

    All pins are used so it must be multiplexed with the LED display.
    It is possible, but a lot of effort, and requires extra components as well.

    It is also complicated on the sender side, needs one extra line to wait for a transition.

    Or it would conflict with the LED display data.

    The PIC16f54 does not have a hardware serial port.

    The 16f716 does have an interrupt on port change, so it could be done with two pins.

    Still more complicated since the master must care for the transition.

    It is a good solution in terms of simplicity and short source code.
    The display goes off during the update, but not really annoying.

    I will have an STM8 circuit ready soon with upto 24 I/O, and hardware serial port. Chips arrived here today.

    Think of a radiation counter. It is not used very often, and the display going off for a short moment every second is totally acceptable. Applications like that.

    If you want a high-grade display, use a LCD or TFT.

    The refresh frequency I have programmed is good as well. It is not true actually, but it looks as if all segments are having even brightness. Technically they don't. That was a big annoyance, far more than the display going off a little during update.
  6. takao21203

    Thread Starter AAC Fanatic!

    Apr 28, 2012
    The displays actually open a range of new possibilities.

    Much smaller controllers like for instance a 16f1503 can be used.

    I added 3 LDRs and 2 pushbuttons.

    4 digits are totally enough to display the mode, and the 10bit value directly.

    Character LCDs are much larger, need a certain voltage for the bias (not so easy to work from a depleted coin cell), and the software interface is complicated to setup.

    The code for the serial LED display is very easy to use.
    The voltage range is really less than 2v to full 5V.
    Only 3 wires.

    My own productivity is much increased.

    Sadly it took me about 2 years to have the idea simply to reset the display each time, then to transmit the data. And also the complicated assembler code made me not wanting to use them at all.

    Next I want to make my radiation counter working...

    I had the display mounted already, but then gave up to search for the schematic how to add the resistors, and how to wire it, and also to adapt the assembler to C. So it was just sitting there, uncompleted as it is.

    One for sure- assembler is almost banned from my work.

    I strongly recommend not to use it at all, if any possible.
  7. MrChips


    Oct 2, 2009
    Why not go to the ultimate solution. Serial LED or LCD displays with backlighting, interfaced with one addressable control line, power and ground.

  8. takao21203

    Thread Starter AAC Fanatic!

    Apr 28, 2012
    Every government funded research and university needs 20 of these.

    Then the manual gets lost and/or the cable, so despite the high price, nobody can or actually is using them.
  9. MrChips


    Oct 2, 2009
    These are custom made instruments. Display labels are added to silk screen during production.
  10. takao21203

    Thread Starter AAC Fanatic!

    Apr 28, 2012
    When I went to college the gear had an utilization rate of not even 1%.

    We also had a PLC class with very old and klunky units floating around everywhere. Actually they were never even just powered up.

    So they could use cardboard imitations.

    What are these? Serial display units? What are they good for? When was the data they were produced? Where are they used?
  11. MrChips


    Oct 2, 2009
    It doesn't matter what they are used for. I am showing an example of multiple displays that are interfaced via a single wire to the controller board.
  12. takao21203

    Thread Starter AAC Fanatic!

    Apr 28, 2012
    OK. Small TFTs also have SPI. And they need additional control signals as well. Also only cost 6 dollar, and can display a number of lines and even graphics.

    However they need a regulated power supply, about 3 volts. If the battery becomes depleted, you need to step up, or the display will go off.

    Big advantage of LED 7seg. They will go down to 1.5V really. Need no regulation.

    The units you show rather raise question for the enclosure. You could step on these probably.
  13. takao21203

    Thread Starter AAC Fanatic!

    Apr 28, 2012
    Programmed the firmware for 3-digit displays today.

    After writing such tables quite many times, it only takes an hour to create the data for a new display. Common Anodes for these.

    Finalized the dual LCD PCB today- also soon will be produced. 2x PIC 16f59, and 1000uH coils for low frequency (to save battery power).
  14. takao21203

    Thread Starter AAC Fanatic!

    Apr 28, 2012
    The 16f59 LCD boards arrived here.

    Same technology. 2x 16f59 controllers.

    Quite expensive, cost me about 8 dollar each.

    On ebay for $15.98 or best offer.
    It takes a while to assemble them, and the firmware + documentation also is a lot of work.

    Differently to Hitachi standard LCD modules, these work from 3V button cells, and contrast does not drop off if the battery runs out more and more.

    I have actually no idea how many uA or mA they use, or what is the MCU frequency. Much lower here for the LCD to save power.