标题: 有没有用过74ls165的?有个问题。 [打印本页]

作者: caotain    时间: 2015-7-12 18:02
标题: 有没有用过74ls165的?有个问题。

作者: caotain    时间: 2015-7-12 18:02
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit CLK=P0^0;                        
sbit SH_LD =P0^2;                     
sbit QH =P0^3;                                
sbit CLKIN =P0^1;  
//unsigned char flag,a;
unsigned char bdata Key;
sbit    K0=Key^0;         //붨òå
sbit    K1=Key^1;         //붨òå
sbit    K2=Key^2;         //붨òå
sbit    K3=Key^3;         //붨òå
sbit    K4=Key^4;
sbit    K5=Key^5;
sbit    K6=Key^6;
sbit    K7=Key^7;

//bit  M0 ,K0J;  //붨òå
uint read_int165(void)
{
  uchar i=0;
  uint read_data=0;
//  CLKIN=1;
  SH_LD=0;                    //Ëø′æêy¾Y      
  _nop_();
  SH_LD=1;
  _nop_();
//  CLKIN=0;
        i=8;
        do
        {CLK=0;
     read_data<<=1;
     if(QH){read_data|=0x01;}
                 
     _nop_();
     CLK=1;        
     _nop_();
  }while(i--);
  return (read_data);
}
void main()
{

  while(1)
  {
     unsigned long  Input=read_int165();//μ÷óÃ165Çy¶ˉ3ìDò
         Key=Input;  //½«êy¾Y′«¸øÎ»±äá¿
         
     P1 = 0xff;          //Çå3y

          //êμÏÖÂö3åêäèë  ′ó¼ò×Dϸìå»á
//    if(K0&K0J)M0=~M0;      
//           K0J=~K0;  
//  
//        if(M0) { P2 = 0x7f;        }//êμÏÖÂö3åêäèë
                if(K0) {   P1 = 0x7f;   }
        if(K1) {   P1 = 0xbf;   }//K1 Îa1걿aÆô·äÃùÆ÷oí2¸öμÆ
        if(K2) {   P1 = 0xdf;   }
  if(K3) {   P1 = 0xef;   }
        if(K4) {   P1 = 0xf7;   }
        if(K5) {   P1 = 0xfb;   }
        if(K6) {   P1 = 0xfd;   }
        if(K7) {   P1 = 0xfe;   }

  }
}


作者: caotain    时间: 2015-7-12 18:03
但是输入全为高电平的话,串行输出还是低,为什么?




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1