用74HC165讀8個按鍵狀態(tài)
本文介紹用74HC165讀8個按鍵狀態(tài)
本文引用地址:http://m.butianyuan.cn/article/201808/384880.htm//程序名稱: 用74HC165讀8個按鍵狀態(tài)
//晶振: 11.0592MHz;
//MCU型號: STC89C52RC;
//電路板型號: EBV-MV(51實驗板);
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//硬件連接:
//EBVn-[VCC] -> MVn-[--VCC--]
//EBVn-[GND] -> MVn-[//GND//]
//MVn-{EX3}-[Y0] -> MVn-{EX2}-[L1]
//MVn-{EX3}-[Y1] -> MVn-{EX2}-[L2]
//MVn-{EX3}-[Y2] -> MVn-{EX2}-[L3]
//MVn-{EX3}-[Y3] -> MVn-{EX2}-[L4]
//MVn-{EX3}-[Y4] -> MVn-{EX2}-[L5]
//MVn-{EX3}-[Y5] -> MVn-{EX2}-[L6]
//MVn-{EX3}-[Y6] -> MVn-{EX2}-[L7]
//MVn-{EX3}-[Y7] -> MVn-{EX2}-[L8]
// -> MVn-{EX2}-(VCC)
// -> MVn-{EX3}-(VCC)
//EBVn-[P10] -> MVn-{EX3}-[A]
//EBVn-[P11] -> MVn-{EX3}-[B]
//EBVn-[P12] -> MVn-{EX3}-[C]
//EBVn-[P13] -> MVn-{EX3}-[G1]
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//實驗結(jié)果:
//控制74HC138的[A,B,C,G1]端口,使[Y0,Y1..Y7]輸出預(yù)期的值,LED實現(xiàn)了流水燈顯示
//--------------------------------------------------------------------------
//------------------------------------------------------
//頭文件;
#include
#define HC165_nPL P3_5
#define HC165_CK P3_6
#define HC165_OUT P3_7
//------------------------------------------------------
void delay(void)
{
unsigned char i,j;
for(i = 250;i > 0;i--)
for(j = 200;j > 0;j--);
}
unsigned char HC165(void)
{
unsigned char i;
unsigned char Temp;
HC165_CK = 1;
HC165_nPL = 0; //HC165讀按鍵
HC165_nPL = 1; //暫停HC165讀按鍵
Temp = 0;
if(HC165_OUT == 1) Temp |= 0x01;
for(i = 0;i 7;i++)
{
HC165_CK = 0;
HC165_CK = 1;
Temp = 1;
if(HC165_OUT == 1)
{
Temp |= 0x01;
}
}
HC165_CK = 0;
return(Temp);
}
//------------------------------------------------------
//程序入口;
void main(void)
{
while(1)
{
P1 = HC165();
delay();
}
}
評論