完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我希望这听起来不像是懒人问题。令人惊奇的是,在MPLABX/XC8项目中,有没有一种最佳的实践/推荐方法来对控制器的所有引脚进行初始化和初始化,特别是如果它的一个40引脚封装。很多针?我们可以在XC8/Engy文件夹中使用PIC18F4620.H文件吗?或者必须手动键入每个端口PIN和tiIS,并将其初始化为H或L?我的意思是,如果有什么方法可以得到所有TIS的PIN名称模板以及初始化目的?任何帮助都是伟大的。
以上来自于百度翻译 以下为原文 Hi everyone I hope this does not sound like a lazy person question.. what is wonder is that is there any best practice/recommended way to TRIS and initialize all pins of a controller in the MPLABX/XC8 project, specially if its a 40 pin package.. lots of pins? Can we use the stock PIC18F4620.h file in the XC8/include folder for this purpose in any way? Or one has to manually type each port-pin and TRIS as well as initialize it to H or L? I mean if there someway to get a template of all the pins names for TRIS as well as initialization purpose? Any help is great. |
|
相关推荐
3个回答
|
|
以上一切都有效!虽然对于8位二进制,二进制更容易可视化。
以上来自于百度翻译 以下为原文 All the above will work! Although for the 8 bit parts binary is easier to visualize. |
|
|
|
对于输出引脚,最好的做法是在使PIN A输出(通过TrISX)之前,将输出状态配置为高电平或低电平(通过LATX),以避免您的代码输出错误的状态,直到初始化代码将输出引脚置于期望的状态中,而没有出现可能出现的故障。LATX值包含与期望值相反的值。(意想不到的“毛刺”的持续时间可以根据手头上的代码/情况而变化)。作为一个例子,PIC16F1937单片机的“LAT”和“端口”寄存器在上电复位(POR)或断电复位(BOR)上有一个不确定的(未知)状态,因此此代码:采用TH。方法:将优于此代码:避免这种方法:
以上来自于百度翻译 以下为原文 For output pins it's a best practice to configure the output state as high or low (via LATx) prior to making the pin an output (via TRISx) to avoid your code outputting the wrong state until your initialization code puts the output pin in the desired state -- without a glitch that could occur if the LATx value contained the opposite value from your desired value. (The duration of the unintended "glitch" could vary depending on the code/situation at hand in conjunction with the Fosc value.) As one example, the PIC16F1937 MCU's 'LAT' and 'PORT' registers have an indeterminate (unknown) state on Power-On Reset (POR) or Brownout Reset (BOR) so this code: Adopt this method: // Pre-configure 'RDO' to a logic 'low' state LATDbits.LATD0 = 0; // Now, *actually* make pin 'RDO' an output pin TRISDbits.TRISD0 = 0; would be preferable to this code: Avoid this method: // *Actually* make pin 'RDO' an output pin TRISDbits.TRISD0 = 0; WARNING: At this point 'RD0' could be a logic 'high' depending on the value of 'LATDbits.LATD0' which is not what this example code wants. This will cause a glitch. // Configure 'RDO' to a logic 'low' state LATDbits.LATD0 = 0; |
|
|
|
你好,NaEEM1234,我道歉,我用一个错误的MCU作为一个例子,但是你的PIC18F4620 MCU的“LAT”和“端口”寄存器也有一个不确定的(未知的)状态,上电复位(POR)或BLUNOUT重置(BOR),所以我的建议对你来说仍然成立。但是关键点是TrISX寄存器有一个*知道。N*状态在上电复位(POR)或断电复位(BOR)-使其输入引脚(高阻抗)-模拟针的细微之处除了上述例子的缘故。总是仔细研究数据表。我希望这些额外的细节也有助于,连同现有的论坛社区的优秀建议给您。在您的项目和/或产品的最好祝愿。最好的问候,肯。
以上来自于百度翻译 以下为原文 Hello naeem1234, My apologies, I used a wrong MCU as an example, but your PIC18F4620 MCU's 'LAT' and 'PORT' registers also have an indeterminate (unknown) state on Power-On Reset (POR) or Brownout Reset (BOR) so my advice to you still stands. But the key point is that the TRISx registers have a *known* state at Power-On Reset (POR) or Brownout Reset (BOR) -- making them input pins (high impedance) -- analog pin subtleties aside for the sake of the above example. Always study the Data Sheet carefully. I hope these additional details help as well, along with the existing Forum Community's excellent advice to you. Best wishes in your project and/or product. Best regards, Ken |
|
|
|
只有小组成员才能发言,加入小组>>
4844 浏览 9 评论
1846 浏览 8 评论
1762 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
2971 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2074 浏览 5 评论
472浏览 1评论
1123浏览 1评论
313浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
375浏览 0评论
270浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-5-13 19:22 , Processed in 0.983996 second(s), Total 82, Slave 66 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号