74HC165 并入串出

编程入门 行业动态 更新时间:2024-10-22 18:39:24

74HC165 并入串出

74HC165 并入串出

/******************************************************** 
程序名:main.C
版  本:Ver1.0
芯  片:AT89C51或STC89C51
晶  体:片外12MHz
编  程: Joey
日  期:2023-11-13
描	 述:通过 74HC165 对 16 按键输入进行扩展
C编译器:Keil C51
注意事项:
重要事项:********************************************************/
#include "REG51.h"#define u8 unsigned char
#define u16 unsigned int/***************************************************************************/
sbit DIN=P1^0;
sbit CLK=P1^2;
sbit SH =P1^1;/***************************************************************************/
void Delay(u16 x)
{while(x--);
}
u16 Read_74HC165D(void)
{u16 i,ReadKey=0;DIN=1;CLK=1;/**** load the data for D0-D7 at onece**/SH =0;SH =1;//read form first level to the second level//first level: the directly output levelfor(i=0;i<16;i++){ReadKey<<=1;	//the first level data will be moved to the fist 8 bitCLK=1;if(DIN)	//read the data output from the first levelReadKey++;Delay(10);CLK=0;}return ReadKey;
}
/***************************************************************************/
void main(void)
{static u16 temp,templast;while(1){temp=Read_74HC165D();if(temp != templast){if(temp != 0xFFFF){P2=temp&0xFF;		//second level to the P2P3=(temp>>8)&0xFF;	//first level to the P3}templast=temp&0xFFFF;}else{P2=temp&0xFF;P3=(temp>>8)&0xFF;}Delay(100000);}
}
/***************************************************************************/

更多推荐

74HC165 并入串出

本文发布于:2023-11-15 03:05:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1592642.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!