1. You can now buy finished microcontroller project from us, Check out the Store for the complete list of projects.
  2. Need a custom project, Send us some details about your project. So that we can quote the price for it.

8051 Interfacing 7segment display with serial input 1.0

Driving a 7segment display with serial input. The 74ls164 is used for serial to parallel connection.

  1. sajiv jess
    Driving a 7segment display with serial input. The 74ls164 is used for serial to parallel connection.

    Sponsored Links

    Circuit Diagram
    [​IMG]
    Assembly Code
    Code (Text):
    1. ORG      00H
    2.     LJMP    MAIN
    3.     ORG    0030H
    4. MAIN:    MOV    SCON,#00000000B    ;Set UART works MODE0
    5. START:  
    6.     JNB    P1.1,A1        ;P1.1 is pressed, jump to the A1
    7.     JNB    P1.2,A2        ;P1.2 is pressed, jump to the A2
    8.     JMP    START
    9. A1:    MOV    R2,#2    ;Set the display number 0808
    10.     CALL    SHOW
    11.     MOV    R2,#0
    12.     CALL    SHOW
    13.     MOV    R2,#0
    14.     CALL    SHOW
    15.     MOV    R2,#8
    16.     CALL    SHOW
    17.     JMP    START
    18. A2:    MOV    R2,#0    ;Set the display number 0808
    19.     CALL    SHOW
    20.     MOV    R2,#8
    21.     CALL    SHOW
    22.     MOV    R2,#0
    23.     CALL    SHOW
    24.     MOV    R2,#8
    25.     CALL    SHOW
    26.     JMP    START
    27.  
    28. SHOW:    MOV    DPTR,#TAB    ;Display Data
    29.     MOV    A,R2
    30.     MOVC    A,@A+DPTR    ;Election code section to read common cathode
    31.     MOV    SBUF,A        ;Serial output
    32. LOOP1:
    33.     JBC    TI,LOOP2    ;Detection TI = 1? Is then transferred LOOP2
    34.     JMP    LOOP1
    35. LOOP2:    RET
    36.  
    37. DELAY:    MOV R4,#10    ;Delay
    38. DELAY0:    MOV R7,#100
    39. DELAY1:    MOV R6,#250
    40.     DJNZ R6,$
    41.     DJNZ R7,DELAY1
    42.     DJNZ R4,DELAY0
    43.     RET
    44. TAB:    DB    0FCH,060H,0DAH,0F2H,066H,0B6H,0BEH,0E0H,0FEH,0F6H,000H    ;0~9 election code
    45.     END
    C Code
    Code (C):
    1. #include <reg51.h>
    2. #include <stdio.h>
    3.  
    4. sbit p11=P1^1;
    5. sbit p12=P1^2;
    6. unsigned char data discode[11]={0XFC,0X60,0XDA,0XF2,0X66,0XB6,0XBE,0XE0,0XFE,0XF6,0x00};//Common cathode serial
    7.  
    8. unsigned char leddis[4]={1,2,3,4};//Memory, several digital control can be defined several
    9.  
    10. void display(void)  //LED display function
    11. {
    12.     unsigned char count;//The number of digital control
    13.      
    14.     for (count=4;count>0;count--)
    15.     {
    16.         SBUF=discode[leddis[count-1]];
    17.         while(TI==0);
    18.         TI=0;
    19.     }
    20. }  
    21. void main()
    22. {
    23.         SCON=0x00;    //Set UART works as MODEO
    24.         leddis[0]=1;    //Display initialization
    25.         leddis[1]=2;
    26.           leddis[2]=3;
    27.           leddis[3]=4;
    28.         display();    //    Display function
    29.  
    30.         while(1)
    31.         {
    32.             if(p11==0)    //P11 key is pressed, display 2008
    33.             {
    34.                 leddis[0]=2;
    35.                 leddis[1]=0;
    36.                 leddis[2]=0;
    37.                 leddis[3]=8;
    38.                 display();
    39.                 p11=1;
    40.             }
    41.             if(p12==0)    //P12 key is pressed, display 0808
    42.             {
    43.                 leddis[0]=0;
    44.                 leddis[1]=8;
    45.                 leddis[2]=0;
    46.                 leddis[3]=8;
    47.                 display();
    48.                 p12=1;
    49.             }      
    50.         }      
    51. }