keil程序看不懂

keil程序看不懂,第1张

0FFH是8位1啊,就是P3口全为1。因为P3口接8个按钮,要读按纽的状态,即P3口为输入口,所以,要求读之前要全为1。

你是要问这结果是与教程序说的结果相反吗?

这么短的程序也看不懂啊

MAIN: MOV P3,#0FFH P3口全为1

LOOP: MOV A,P3 读P3口了,并送到A中

MOV P1,A 把A中的按纽状态送到P1口,控制8个LED灯,对应位的LED就亮了

LJMP LOOP

#include <reg51.h>

#include <stdio.h>

#define uchar unsigned char

#define uint unsigned int

sbit RecPort = P3 ^ 2 //接受端口

sbit SendPort = P3 ^ 3 //发送端口

uchar TimeSet, KeyPorts

//初始化端口

void InitPort()

{

RecPort = 1

SendPort = 0

}

//初始化特殊功能寄存器

void InitSFR()

{

TMOD = 0x11

TR0 = 1

}

void InitValue(){}

//初始化系统

void InitSystem()

{

InitPort()

InitSFR()

InitValue()

}

//清空屏幕

void ClearScreen()

{

TI = 0

SBUF = 254

while (!TI)

TI = 0

SBUF = 1

while (!TI)

}

//延时1ms

Delay1ms()

{

uint i

for (i = 110i != 0i--)

}

//主程序

void main(void)

{

//初始化

InitSystem()

ClearScreen()

while (1)

{

KeyPorts = P1

//当接收口有效时

if (RecPort)

{

TL0 = 0

TH0 = 0

//根据四个不同的按键,分别设置延时

KeyPorts = KeyPorts ^ 0xff

if (KeyPorts &0x01)

{

TimeSet = 50

}

else if (KeyPorts &0x02)

{

TimeSet = 70

}

else if (KeyPorts &0x04)

{

TimeSet = 90

}

else

{

TimeSet = 110

}

while (TH0 <TimeSet)

SendPort = 1

//延时一秒,用于缓冲

Delay1ms()

SendPort = 0

}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/11237153.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存