完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我刚刚开始使用16F1827来替换我的项目中的16F628,并且有一个关于使用PORTX和LATX来读取和写入端口的问题。从我的阅读中,传统的智慧是写入LATx并从Poxx读取。但是,阅读16F1827数据表。我找到了这一行(第122页,也在其他页上):注1:写到端口实际上写到相应的LATA寄存器。从PORTA寄存器中读取的是实际I/OPin值的返回值。我的理解是,将端口写入到LAT寄存器中,而不必实际写入代码中的LAT寄存器。如果是这样的话,任何人都可以了解BCF和BSF在端口上的操作是否为B。E相同吗?
以上来自于百度翻译 以下为原文 I've just started playing with the 16F1827 to replace the 16F628A in my projects and have a question relating to the use of PORTx and LATx for reading from and writing to the Ports. From my reading, the conventional wisdom is to write to LATx and read from PORTx. However, reading the 16F1827 datasheet, I find this line (page 122, but also on other pages): Note 1: Writes to PORTA are actually written to corresponding LATA register. Reads from PORTA register is return of actual I/O pin values. My understanding of that is that writes to the PORT write to the LAT register without having to actually write to the LAT register in code. If that is the case, can anyone shed any light on whether BCF & BSF operations on a PORT would be the same? |
|
相关推荐
7个回答
|
|
坚持使用传统的智慧。在内部,所有写都写在同一个锁存器上,唯一的区别是读什么。BSF或BCF指令都是(读修改写)。如果BSF一个端口寄存器,它从端口(即PIN)读取,修改一个位,并写回公共锁存器。您的BSF是一个LAT寄存器,它从内部锁存器读取,修改一个位,并写入到公共锁存器。因此,总是在LAT寄存器上使用BSF和BCF,而不是端口寄存器。
以上来自于百度翻译 以下为原文 Stick with the conventional wisdom. Internally, all writes write to the same latch, the only difference is what is READ. A BSF or BCF instruction does both (read-modify-write). If you BSF a PORT register, it reads from the PORT (i.e. the pins), modifies one bit, and writes back to the common latch. If you BSF a LAT register, it reads from the internal latch, modifies one bit, and writes back to the common latch. So, always use BSF and BCF on the LAT register, not the PORT register. |
|
|
|
|
|
|
|
我注意到你的回复,它证实了我的假设。在16F1825数据表中,请查看12:1(PGE116)用于初始化PurtAcLePar和LATAL LATAARE两者是否真的需要的例子?
以上来自于百度翻译 以下为原文 I readed your reply and It confirms what I have supposed. In the 16F1825 data sheet please look at the example 12-1(page116) for Initializing PORTA Clear PORTA and Clear LATA Are both really needed? |
|
|
|
不,当你写整个端口时,它们都做完全一样的事情,所以你只需要一个或另一个。
以上来自于百度翻译 以下为原文 No. When you write the entire port, they both do exactly the same thing, so you only need one or the other. |
|
|
|
谢谢你的回复。我用了16F1825已经2年了,从来没有清除过拉塔,只有PATA。----------------我有一个更不相关的问题,PIC16F1825和模拟输入将使用一个比较器,并且现有的板具有与PIN 13(RA0)PIN 12(RA1)连接的模拟信号。没有连接。我需要比较输入与GND我有程序正输入到引脚13和负到PIN 12ANSELA和TrISA两个000000比较器工作良好(我检查COMP)。输出在RA2),但有线引脚GND只为测试。我的要求是:如果我清除TrISA,1和设置RA1=0(或拉塔,1=0),它可以取代连接的RA1(PAN12)到GND,使它不连接?我会感谢你的帮助。考试在董事会上非常困难。
以上来自于百度翻译 以下为原文 Thank you for the reply. I had used 16F1825 for 2 years and have never cleared LATA, only the portA. ---------------------- I have a question more a less related, with pic16F1825 and analog inputs I will use one comparator and the existing board have the analog signal wired to pin 13 (RA0) Pin 12 (RA1) is no conected. I need to compare the input with GND I have programed positive input to pin 13 and negative to pin 12. ANSELA and TRISA both 00000011 Comparator is working fine (I check comp. output at RA2) , but have wired the pin to GND only for the test. My ask is: if I clear the TRISA,1 and set RA1=0 (or LATA,1=0) , may it replace the wiring of RA1 (pin12) to GND and leave it unconected? I will apreciate your help. Tests are very dificult on the board. |
|
|
|
这很好。正如我所说,你可以做一个或另一个。这将是一种工作,好。这意味着你正在比较一个逻辑低,而不是地面,但如果引脚没有加载任何方式,它将非常接近地面。
以上来自于百度翻译 以下为原文 and that is fine. As I said, you can do one or the other. That will sort of work ok. It means you're comparing against a logic low, not ground, but if the pin is not loaded in any way, it will be very close to ground. |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5183 浏览 9 评论
2005 浏览 8 评论
1932 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3178 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2229 浏览 5 评论
739浏览 1评论
624浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
510浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
637浏览 0评论
535浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-27 17:27 , Processed in 1.338918 second(s), Total 88, Slave 72 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号