acdt/board/Src/hc165.c

42 lines
855 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "hc165.h"
//初始化74hc165
void _74hc165_init(void)
{
HC165_LD(1); //LD拉高不读取按键状态
HC165_CLK(1); //时钟拉高,便于产生上升沿
}
//读取74HC165
uint16_t _74hc165_read_byte(void)
{
unsigned char i;
unsigned int temp = 0;
HC165_LD(0); //LD拉低读取按键状态
delay_us(1);
HC165_LD(1); //LD拉高停止按键读取
delay_us(1);
if(HC165_DAT == 1) //等于1即并行输入D7引脚的按键被按下
{
temp |= 0x01; //最低位置1表示按键被按下反之则没按键被按下
}
for(i = 0; i < 15; i ++) //因为最高位不用移位即可读取,故循环(8-1)次依次把次高位移到最高位第一级74HC165优先读取
{
temp = temp << 1;
HC165_CLK(0); //HC165_CLK = 0 ——> HC165_CLK = 1 产生上升沿次高位D(n-1)移到高位D(n)
delay_us(1);
HC165_CLK(1);
// delay_us(1);
if(HC165_DAT == 1)
{
temp |= 0x01;
}
// delay_us(1);
}
return temp;
}