利用89C51的P1口监测某一按键开关
1、在Keil uVision4上编写程序
(1)程序如下
#include<reg51.h>
#include<stdio.h>
sfr P1
=0x90;
sbit p1_0
=P1
^0;
sbit p1_7
=P1
^7;
main()
{
unsigned char i
;
while(1)
{
P1
=0x80;
do{}while(p1_7
==1);
do{}while(p1_7
==0);
p1_0
=1;
for(i
=0;i
<255;i
++);
}
}
(2)编译通过 (3)生成 .hex 文件
2、在proteus 8上仿真
(1)连接电路图 (2)将在Keil里生成的hex文件添加到89C51芯片中 (3)添加完成后运行
(4)运行结果
3、结果分析
观察到发光二极管闪烁,说明成功用89C51的P1空监测到按键开关