#include <reg51.h>
#include <intrins.h>
//--定义使用的IO口--//
#define GPIO_LED P0
sbit IN_PL = P1^6; //主P1.6 接 CPU P1.4。
sbit IN_Data = P1^7; //数据通过P1.7脚移进单片机内处理
sbit SCK = P3^6;
//--声明全局函数--//
unsigned char Read74H165(void);
/*******************************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void main()
{
unsigned char h165value;
GPIO_LED = 0;
while(1)
{
h165value = Read74H165();
if(h165value != 0xFF)
{
GPIO_LED = ~h165value;
}
}
}
/*******************************************************************************
* 函 数 名 : Read74H165
* 函数功能 : 使用165读取一个字节数据
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
unsigned char Read74H165(void)
{
unsigned char i;
unsigned char indata;
IN_PL = 0;
_nop_(); //短暂延时 产生一定宽度的脉冲
IN_PL = 1; //将外部信号全部读入锁存器中
_nop_();
indata=0; //保存数据的变量清0
for(i=0; i <8; i++)
{
indata = indata < <1; //左移一位
SCK = 0; //时钟置0
_nop_();
indata |= IN_Data;
SCK = 1; //时钟置1
}
return(indata);
}
定义P1^6,p1^7和p3^6这个地方不懂????简单的开发板,其中连线是P0连接数码管,键盘连接74HC165,其中P1P2P3都没用线连起来,为什么还能用到那三个口呢?求助,谢谢