interfacing two 74HC374 on single port of 8051

Discussion in 'Embedded Systems and Microcontrollers' started by Rawatraj, Apr 18, 2013.

  1. Rawatraj

    Thread Starter New Member

    Jul 24, 2012
    1
    0
    Hello sir
    i am trying to interface two 74hc374 with 8051 on single port but getting problem, here is my condition and my program also,
    Q: I have 16 switches as a input 1st 8 switch used for 1st 74hc374 and next 8 switch used for 2nd 74hc374,at the output of 74HC374 we have LED's. if we will press switch one first output pin of 74hc374 is high (i.e LED1 high) same upto 16th switch.

    Code ( (Unknown Language)):
    1.  
    2. #include<reg52.h>
    3. sbit row1 = P1^0;
    4. sbit row2 = P1^1;
    5. sbit row3 = P1^2;
    6. sbit row4 = P1^3;
    7.  
    8. sbit col1 = P1^4;
    9. sbit col2 = P1^5;
    10. sbit col3 = P1^6;
    11. sbit col4 = P1^7;
    12.  
    13. sbit LED0 = P2^0;
    14. sbit LED1 = P2^1;
    15. sbit LED2 = P2^2;
    16. sbit LED3 = P2^3;
    17. sbit LED4 = P2^4;
    18. sbit LED5 = P2^5;
    19. sbit LED6 = P2^6;
    20. sbit LED7 = P2^7;
    21.  
    22. sbit clock1=P3^0;
    23. sbit clock2=P3^1;
    24.  
    25.  
    26.  void check_col1()
    27. {
    28.   clock1=clock2=0;
    29.  row1=row2=row3=row4=1;
    30.  row1=0;
    31.  if(col1==0)
    32.  {
    33.     clock1 = 1;
    34.     LED0 = 1;
    35.     clock1 = 0;
    36.  }
    37.     row1=1;
    38.     row2=0;
    39.  if(col1==0)
    40.  {
    41.    clock1=1;
    42.    LED1=1;
    43.    clock1 = 0;
    44.  }
    45.  row2=1;
    46.  row3=0;
    47.  if(col1==0)
    48.  {
    49.   clock1=1;
    50.   LED2=1;
    51.   clock1 = 0;
    52.  }
    53.  row3=1;
    54.  row4=0;
    55.  if(col1==0 )
    56.  {
    57.    clock1=1;
    58.    LED3=1;
    59.    clock1 = 0;
    60.  }
    61.   row4=1;
    62. }
    63.  
    64. void check_col2()
    65. {
    66.   clock1=clock2=0;
    67.   row1=row2=row3=row4=1;
    68.   row1=0;
    69.   if(col2==0)
    70.   {
    71.     clock1=1;
    72.     LED4=1;
    73.     clock1 = 0;
    74.   }
    75.   row1=1;
    76.   row2=0;
    77.   if(col2==0)
    78.   {
    79.     clock1 = 1;
    80.     LED5=1;
    81.     clock1 = 0;
    82.  }
    83.   row2=1;
    84.   row3=0;
    85.   if(col2==0)
    86.   {
    87.     clock1=1;
    88.     LED6=1;
    89.     clock1 = 0;
    90.   }
    91.   row3=1;
    92.   row4=0;
    93.   if(col2==0)
    94.   {
    95.    clock1=1;
    96.    LED7=1;
    97.    clock1 = 0;
    98.   }
    99.    row4=1;
    100. }
    101.  
    102.  void check_col3()
    103. {
    104.  clock1=clock2=0;
    105.  row1=row2=row3=row4=1;
    106.  row1=0;
    107.  if(col3==0 )
    108.  {
    109.    clock2=1;
    110.    LED0=1;
    111.    clock2 = 0;
    112.  }
    113.     row1=1;
    114.     row2=0;
    115.  if(col3==0)
    116.  {
    117.    clock2 = 1;
    118.    LED1=1;
    119.    clock2 = 0;
    120.    }
    121.  row2=1;
    122.  row3=0;
    123.  if(col3==0)
    124.  {
    125.    clock2=1;
    126.    LED2=1;
    127.    clock2 = 0;
    128.  }
    129.  row3=1;
    130.  row4=0;
    131.  if(col3==0)
    132.  {
    133.    clock2 = 1;
    134.    LED3=1;
    135.    clock2 = 0;
    136.  }
    137.   row4=1;
    138. }
    139.  
    140. void check_col4()
    141. {
    142.    clock1=clock2=0;
    143.   row1=row2=row3=row4=1;
    144.   row1=0;
    145.   if(col4==0)
    146.   {
    147.    clock2=1;
    148.    LED4=1;
    149.    clock2 = 0;
    150.   }
    151.   row1=1;
    152.   row2=0;
    153.   if(col4==0)
    154.   {    
    155.    clock2 = 1;
    156.    LED5=1;
    157.    clock2 = 0;
    158.   }
    159.   row2=1;
    160.   row3=0;
    161.   if(col4==0 )
    162.   {
    163.     clock2=1;
    164.     LED6=1;
    165.    clock2 = 0;
    166.   }
    167.   row3=1;
    168.   row4=0;
    169.   if(col4==0 )
    170.   {
    171.     clock2=1;
    172.     LED7=1;
    173.    clock2 = 0;
    174.   }
    175.    row4=1;
    176. }
    177.  
    178. void main()
    179. {
    180.  
    181.  LED0=LED1=LED2=LED3=LED4=LED5=LED6=LED7=0;
    182.  clock1=clock2=0;
    183.  while(1)
    184.  {
    185.  
    186.   col1=col2=col3=col4=1;  //input port
    187.   row1=row2=row3=row4=0;
    188.   if(col1==0)
    189.  
    190.    {
    191.      check_col1 ();
    192.                
    193.    }
    194.    if(col2==0)
    195.    {
    196.  
    197.    check_col2();
    198.    
    199.   }      
    200.    if(col3==0)
    201.    {
    202.    
    203.      check_col3();
    204.    
    205.    }
    206.    if(col4==0)
    207.    {
    208.    
    209.     check_col4();
    210.    
    211.    }
    212.  }
    213. }
    214.  
    main problem is 1st 8 switch are working properly but when pressing 9th switch all the LEDs are high together of 2nd 74HC374.[​IMG]
     
    Last edited by a moderator: Apr 18, 2013
Loading...