TA的每日心情 | 怒 3 小时前 |
---|
签到天数: 85 天 [LV.6]常住居民II
三级逆天
- 积分
- 53741
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区
您需要 登录 才可以下载或查看,没有账号?立即注册
×
<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">学习单片机最基础、最重要的就是掌握I/O口的使用。会使用I/O,也就具备了进一步深入学习的基础和条件。51单片机P0口比较特殊,本文就带你死磕P0口,扫清对它的一切困惑。快来看看下面几个小问题你都搞清楚没有?<ul style='margin: 0px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="margin: 0px; padding: 0px; font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; list-.: none; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);"><li style="list-style: none; margin: 0px; padding: 0px; word-wrap: break-word; box-sizing: border-box;" .="padding: 0px; margin: 0px; list-.: none;"><div style="margin: 0px 0px 10px; padding: 0px; word-wrap: break-word; box-sizing: border-box;" .="font-family: inherit;">0口为什么要接上拉电阻?<li style="list-style: none; margin: 0px; padding: 0px; word-wrap: break-word; box-sizing: border-box;" .="padding: 0px; margin: 0px; list-.: none;"><div style="margin: 0px 0px 10px; padding: 0px; word-wrap: break-word; box-sizing: border-box;" .="font-family: inherit;">吸电流和拉电流有什么区别?<li style="list-style: none; margin: 0px; padding: 0px; word-wrap: break-word; box-sizing: border-box;" .="padding: 0px; margin: 0px; list-.: none;"><div style="margin: 0px 0px 10px; padding: 0px; word-wrap: break-word; box-sizing: border-box;" .="font-family: inherit;">什么是准双向I/O?什么是漏极开路输出?<li style="list-style: none; margin: 0px; padding: 0px; word-wrap: break-word; box-sizing: border-box;" .="padding: 0px; margin: 0px; list-.: none;"><div style="margin: 0px 0px 10px; padding: 0px; word-wrap: break-word; box-sizing: border-box;" .="font-family: inherit;">什么是推挽式输出?<li style="list-style: none; margin: 0px; padding: 0px; word-wrap: break-word; box-sizing: border-box;" .="padding: 0px; margin: 0px; list-.: none;"><div style="margin: 0px 0px 10px; padding: 0px; word-wrap: break-word; box-sizing: border-box;" .="font-family: inherit;">0到底怎样做总线复用?<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">P0口的结构<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">1、P0的8位皆为漏极开路输出(Open Drain,OD),千万不要误解为图腾式输出,每个引脚可驱动8个LS型TTL负载;<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">2、P0内部无上拉电阻,执行输出功能时,外部必须接上拉电阻(10kΩ即可);<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">3、若有执行输入功能,必须先输出高电平(1)才能读取该口所连接的外部数据;<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">4、若连接外部存储器,则P0可作为地址总线(A0~A7)及数据总线(D0~D7)的复用引脚,此时内部具有上拉电阻,不用外接。
<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">0口结构图<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">由上图可见,P0口由输入缓冲器、锁存器、切换开关、一个与非门、一个与门及场效应管驱动电路构成,下面逐个分析。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">输入缓冲器<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">在P0口,有两个三态的缓冲器。三态门有三个状态,即在高电平、低电平,高阻状态(或称为禁止状态),大家看上图,上面一个是读锁存器的缓冲器,也就是说,要读取D锁存器输出端Q的数据,那就得使读锁存器的这个缓冲器的三态控制端有效。下面一个是读引脚的缓冲器,要读取P0.X引脚上的数据,也要使标号为‘读引脚’的这个三态缓冲器的控制端有效,引脚上的数据才会传输到我们单片机的内部数据总线上。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">D锁存器<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">51单片机的32根I/O口线中都是用一个D触发器来构成锁存器的。上图中的D锁存器,D端是数据输入端,控制端CP是时序控制信号输入端,Q是输出端,Q非是反向输出端。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">对于D触发器来讲,当D输入端有一个输入信号,如果这时控制端CP没有信号(也就是时序脉冲没有到来),这时输入端D的数据是无法传输到输出端Q及反向输出端Q非的。如果时序控制端CP的时序脉冲一旦到了,这时D端输入的数据就会传输到Q及Q非端。数据传送过来后,即使CP时序控制端的时序信号消失,输出端还会保持着上次输入端D的数据(即把上次的数据锁存起来了)。如果下一个时序控制脉冲信号来了,这时D端的数据才再次传送到Q端,从而改变Q端的状态。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">多路开关<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">多路开关:在51单片机中,如果需要外扩存储器时,P0就可以复用为‘地址/数据’总线。多路选择开关就是用于选择是做为普通I/O口使用还是作为‘数据/地址’总线使用的选择开关。大家看上图,当多路开关与下面接通时,P0口是作为普通的I/O口使用的,当多路开关是与上面接通时,P0口是作为‘地址/数据’总线使用的。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">输出驱动部份<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">输出驱动部份:从上图中我们已看出,P0口的输出是由两个MOS管组成的推拉式结构,也就是说,这两个MOS管一次只能导通一个,当V1导通时,V2就截止,当V2导通时,V1截止。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">漏极开路输出<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">如下图,单片机P1,P2,P3口都可以理解成左图,注意vcc下面有个电阻(约30k),因此可以理解成:引脚拉出电流能力弱。地那边没有电阻,可以理解成引脚吸入电流能力强。而P0口,可以理解成右图。这就是集电极开路输出,也叫集电极开路OC输出,(注意单片机引脚内部是MOS管,应该是漏极开路OD输出)。可以看出,当CTR=1时,三极管导通,引脚被接地;当ctr=0时,三极管截止,引脚浮空,也叫三态。这个端口这么做的目的是考虑P0口肩负读写数据和地址复用,因此,P0口做出输出时要加合适的上拉电阻。
<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">
<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">
<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">吸电流or拉电流<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">上面我们已经知道单片机P1,P2,P3口有上拉电阻(约30k),因此引脚拉出电流能力弱。对地那边没有电阻,可以理解成引脚吸入电流能力强。所以51单片机I/O口通常设计成吸电流的形式。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">以驱动LED发光二极管为例,正向偏压时LED两端约有1.7V左右管压降,驱动LED的电流以10~20mA为宜。P1、P2、P3内部具有30kΩ上拉电阻,若要拉出10~20mA电流是不可能的(5V/30k=0.1667mA)。但采用吸电流的方式,电流就大多了。
<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">从P1口吸电流和拉电流驱动LED实验效果,可以看出LED发光强度有明显区别:<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);"><div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">1口吸电流<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);"><div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">1口拉电流<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">准双向I/O<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">“准”就是“基本上”“勉强算”的意思,“准双向口”不是正真的双向口。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">51单片机P1、P2、P3有固定的内部上拉电阻,当用做输入时被拉高,低则要靠外部电路拉低,当这三个准双向I/O口作输入口使用时,要向该口先写1,使下面的MOS管截止,以防止被拉低。这样的I/O口无高阻的“浮空”状态,不是真正的双向I/O。
<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">0口的真双向指的是它被用作地址/数据端口时,只有在这个时候,P0口才处于两个开关管推挽状态;当两个开关管都关闭时,会出现高阻状态。双向与准双向,根本原则是双向包含了高阻这个状态,而不在于是否需要先写1或者不写,P1~P3口因为有内部上拉电阻,因此无论如何不是双向;P0口内部无上拉电阻,在处于数据/地址功能时,自动完成三态的转换,是双向,处于一般I/O口时,如果不接外部上拉,而且先向端口写了1,那么就处于高阻状态,此时,它也是一个人为的双向口,这与它处于地址/数据功能时的自动双向有区别,以及与P1~P3处于输入时输出锁存器为1是有区别的。跟I2C总线上那种漏极开路或者集电极开路结构差不多,通过上拉电阻(或者下拉电阻)来提供一种电平的驱动.<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">准双向口在做为输入使用时,实际上还是一种输出状态。而真正的双向IO口,有方向控制寄存器,作为输入使用时输出部分被断开。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">双向口与准双向口的区别为双向口有高阻态,输入为真正的外部信号,准双向口内部有上拉,故高电平为内部给出不是真正的外部信号,软件做处理时都要先向口写“1”以断开开关连接。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">图腾式输出<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">图腾式输出(Totem Pole 的音译),此结构电路有点像印第安人的图腾柱,所以叫图腾式输出。输出级分别采用一个NPN型晶体管和一个PNP型晶体管,NPN管集电极接正电源(或接地),发射极接下面PNP管的发射极,同时输出;PNP管的集电极接地(或负电源)。两管的基极同时接前级的控制端。上下两管输出管,从直流的角度看是串联,从交流的角度看是并联,两管发射极连接处为输出端,实际是一对射极跟随器。追随输入电平,上管导通,下管截止,输出高电平;上管截止,下管导通,输出低电平,形成类似推挽式的输出方式。
<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">0口的各单元部件已了解清楚了,下面我们就来研究一下P0口做为I/O口及地址/数据总线使用时的具体工作过程。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">
<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">作为I/O端口使用时<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">当多路开关的控制信号为0(低电平)时,多路开关是与锁存器的‘Q非’端相接的,此时P0口作为I/O口线使用。多路开关的控制信号同时还与与门的一个输入端是相接的,我们知道与门的逻辑是“全1出1,有0出0”,那么当控制信号是0的话,这时与门输出的也是一个0(低电平),V1管就截止。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">0口用作I/O口线时输出状态的工作过程:当写锁存器信号CP有效,数据总线的信号→锁存器的输入端D→锁存器的反向输出Q非端→多路开关→V2管的栅极→V2的漏极到输出端P0.X。由于V1管是截止的,所以作为输出口时,P0是漏极开路输出,当驱动上接电流负载时,需要外接上拉电阻。
<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">读引脚<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">读引脚数据时,读引脚缓冲器打开(即三态缓冲器的控制端要有效),通过内部数据总线输入,请看下图(红色箭头)。但应注意先向口线写1,以截止V2管,以免引脚电平被内部拉低。
<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">读锁存器<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">通过打开读锁存器三态缓冲器读取锁存器输出端Q的状态。在输入状态下,从锁存器和从引脚上读来的信号一般是一致的,但也有例外。例如,当从内部总线输出低电平后,锁存器Q=0,Q非=1,场效应管T2开通,端口线呈低电平状态。此时无论端口线上外接的信号是低电乎还是高电平,从引脚读入单片机的信号都是低电平,因而不能正确地读入端口引脚上的信号。又如,当从内部总线输出高电平后,锁存器Q=1,Q非=0,场效应管T2截止。如外接引脚信号为低电平,从引脚上读入的信号就与从锁存器读入的信号不同。为此,8051单片机在对端口P0~P3的输入操作上,有如下约定:凡属于读-修改-写方式的指令,从锁存器读入信号,其它指令则从端口引脚线上读入信号。
<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">读-修改-写指令的特点是,从端口输入(读)信号,在单片机内加以运算(修改)后,再输出(写)到该端口上。下面是几条读-修改-写指令的例子。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">ANL P0,#立即数 0&立即数→P0<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">ORL P0,A 0|A→P0<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">INC P1 ;P1+1→P1<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">DEC P3 ;P3-1→P3<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">CPL P2 ;~P2→P2<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">这样安排的原因在于读-修改-写指令需要得到端口原输出的状态,修改后再输出,读锁存器而不是读引脚,可以避免因外部电路的原因而使原端口的状态被读错。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">作为地址/数据复用口<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">在访问外部存储器时P0口作为地址/数据复用口使用。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">这时多路开关‘控制’信号为‘1’,‘与门’解锁,‘与门’输出信号电平由“地址/数据”线信号决定;多路开关与反相器的输出端相连,地址信号经“地址/数据”线→反相器→V2场效应管栅极→V2漏极输出。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">例如:控制信号为1,地址信号为“0”时,与门输出低电平,V1管截止;反相器输出高电平,V2管导通,输出引脚的地址信号为低电平。
<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">反之,控制信号为“1”、地址信号为“1”,“与门”输出为高电平,V1管导通;反相器输出低电平,V2管截止,输出引脚的地址信号为高电平。请看下图:
<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">可见,在输出“地址/数据”信息时,V1、V2管是交替导通的,负载能力很强,可以直接与外设存储器相连,无须增加总线驱动器。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">P0口又作为数据总线使用。在访问外部程序存储器时,P0口输出低8位地址信息后,将变为数据总线,以便读指令码(输入)。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">在取指令期间,“控制”信号为“0”,V1管截止,多路开关也跟着转向锁存器反相输出端Q非;CPU自动将0FFH(11111111,即向D锁存器写入一个高电平‘1’)写入P0口锁存器,使V2管截止,在读引脚信号控制下,通过读引脚三态门电路将指令码读到内部总线。请看下图
<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">如果该指令是输出数据,如MOVX @DPTR,A(将累加器的内容通过P0口数据总线传送到外部RAM中),则多路开关“控制”信号为‘1’,“与门”解锁,与输出地址信号的工作流程类似,数据据由“地址/数据”线→反相器→V2场效应管栅极→V2漏极输出。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">如果该指令是输入数据(读外部数据存储器或程序存储器),如MOVX A,@DPTR(将外部RAM某一存储单元内容通过P0口数据总线输入到累加器A中),则输入的数据仍通过读引脚三态缓冲器到内部总线,其过程类似于上图中的读取指令码流程图。<div style='margin: 0px 0px 10px; padding: 0px; text-align: justify; color: rgb(100, 100, 100); text-transform: none; text-indent: 0px; letter-spacing: normal; font-family: myFont, "Microsoft YaHei"; font-size: 16px; font-style: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; background-color: rgb(255, 255, 255); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' .="font-family: 微软雅黑, 宋体, 黑体, Arial, Helvetica, sans-serif; color: rgb(47, 47, 47); font-size: 16px; background-color: rgb(204, 232, 207);">通过以上的分析可以看出,当P0作为地址/数据总线使用时,在读指令码或输入数据前,CPU自动向P0口锁存器写入0FFH,破坏了P0口原来的状态。因此,不能再作为通用的I/O端口。大家以后在系统设计时务必注意,即程序中不能再含有以P0口作为操作数(包含源操作数和目的操作数)的指令 |
|