完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,在运行时配置PIC 32中选择的IO引脚作为输入和输出的最佳方式是什么?在操作过程中,我需要配置一个引脚作为输出和其他作为输入。然后另一个作为输出,剩下的作为输入。谢谢。
以上来自于百度翻译 以下为原文 Hi, What is the best way of configuring the selected IO pins in PIC 32 as input and output during runtime. During the operation I need to configure one pin as output and others as input. Then again other as output and remaining as input. Thanks. |
|
相关推荐
12个回答
|
|
|
|
|
|
正如Dario所提到的,通过在main()函数的开头向TRISx寄存器写入。这是您总是这样做的,所以我不理解您的队列的意义。
以上来自于百度翻译 以下为原文 As Dario mentioned, by writing to the TRISx registers at the start of your main() function. That is they way you would always do it, so I don't understand the point of your quesiton. |
|
|
|
如果在运行时您关心速度,那么使用TRISxSET、TRISxCLR和TRISxINV寄存器进行端口引脚方向的原子切换。
以上来自于百度翻译 以下为原文 If speed is your concern during run time, then use TRISxSET, TRISxCLR and TRISxINV register for the atomic switching of port pins direction. |
|
|
|
你好,我使用的是PIC32 MX795F512L控制器。我在我的应用中使用64个数字输入输出引脚。当我设置64个引脚中的任何一个作为输出,其余作为输入,并且不连接它们或以任何方式短路时,所有的引脚都设置为高。如果我不把输入和输出管脚相互连接,输入管脚处的电压应该等于零伏,但我读到的电压和输出端口相同。下面给出我使用的一段代码:首先我使用LAT电阻器将引脚状态设置为低,并且它们使用TRIS电阻器将所有引脚设置为输入:(我只对第一组16个引脚传递代码)LATBbits.LATB2=0;//将引脚设置为LOW引脚LATBbits.LATB3=0;LATBbits.LATBbits.LATB4=0;LATBbits.LATBbits.LATB5=0;LATE比特.LATB5=0;LATE比特.LATE8=0;LAT比特.LATE8=0;LATG比特.LATG比特.LATG8=0;LATG比特.LATG7=0;LATG比特.LATG比特.LATG7=0;LATE比特.LATE比特.LATE8=0;LATG比特.LATG比特.LATG7=0;LATG比特.LATG比特.LATG7=0;LATG比特.LATG比特.LATG7=0;LATG比特.LATG7=0;LATG比特.LATG7=0;LATG比特.LATG比特.LATG7=0;LATG比特.LATG7=0;LATG比特2=1;//设置引脚为inpuTRISB比特.TRISB3=1;TRISB比特.TRISB4=1;TRISB比特.TRISB4=1;TRISB比特.TRISB5=1;TRI赛比特.TRI TRI TRISE9=1;TRI赛比特.TRISE比特.TRIS9=1;TRI赛比特.TRISE比特.TRISE9=1;TRI赛比特.TRISE比特.TRISE9=1=1;TRISG比特.TRISG比特.TRISG8=1;TRISG比特.TRISG比特.TRISG7=1;TRISG比特.TRISG比特.TRISG7=1;TRISG比特.TRISG比特.TRISG比特.TRISG7=1=1;TRISG比特.TRISGTRISE7=1;TRITRISE6=1;TRISEbits.TRISE5=1;直到这里所有的引脚电压读数为0.1366V左右。然后我将特定的引脚作为输出并将其设置为high.TRISBbits.TRISB2=0;//设置为输出pinLATBbits.LATB2=1;
以上来自于百度翻译 以下为原文 Hi, I am using PIC32MX795F512L controller. I am using 64 Digital input output pins in my application. When i set any one of the 64 pins as output and rest as input and don't connect them or short them in any way, all the pins are set to high. If I don't connect the input and output pins with each other, the voltage at input pins should be equivalent to zero volts but i am reading same voltage as output port. The piece of code i am using is given below: First I set the pin state to low by using LAT resistors and them set all pin to input using TRIS resisters:(I am only pasiting code for first set of 16 pins) LATBbits.LATB2 = 0; // setting pins as LOW pin LATBbits.LATB3 = 0; LATBbits.LATB4 = 0; LATBbits.LATB5 = 0; LATEbits.LATE9 = 0; LATEbits.LATE8 = 0; LATGbits.LATG8 = 0; LATGbits.LATG7 = 0; LATGbits.LATG6 = 0; LATCbits.LATC4 = 0; LATCbits.LATC3 = 0; LATCbits.LATC3 = 0; LATCbits.LATC1 = 0; LATEbits.LATE7 = 0; LATEbits.LATE6 = 0; LATEbits.LATE5 = 0; TRISBbits.TRISB2 = 1; // setting pins as input pin TRISBbits.TRISB3 = 1; TRISBbits.TRISB4 = 1; TRISBbits.TRISB5 = 1; TRISEbits.TRISE9 = 1; TRISEbits.TRISE8 = 1; TRISGbits.TRISG8 = 1; TRISGbits.TRISG7 = 1; TRISGbits.TRISG6 = 1; TRISCbits.TRISC4 = 1; TRISCbits.TRISC3 = 1; TRISCbits.TRISC3 = 1; TRISCbits.TRISC1 = 1; TRISEbits.TRISE7 = 1; TRISEbits.TRISE6 = 1; TRISEbits.TRISE5 = 1; Till here all the pins voltage read around 0.1366V Then i make particular pin as output and set it as high. TRISBbits.TRISB2 = 0; // setting as output pin LATBbits.LATB2 = 1; // set the pin as high but after this step all pins read 3.2V. Any suggestions... Thanks |
|
|
|
输入引脚是连接到任何东西,还是浮动?
以上来自于百度翻译 以下为原文 Are the input pins connected to anything, or floating? |
|
|
|
嗨,这些引脚连接到测试端子,在那里我可以测量电压或者将输出引脚连接到任何输入引脚。或者任何其他方法来检查引脚是否浮动,我有点非常新的PIC32。
以上来自于百度翻译 以下为原文 Hi, These pins are connected to the test terminals where i can measure the voltage or connect the output pin to any of the input pins. Or any other way to check whether the pins are floating, i am kind of very new to PIC32. |
|
|
|
测试仪可以。但是,你确信你的代码不是因为某种原因反复重启吗?
以上来自于百度翻译 以下为原文 Tester is ok. But, are you sure your code is not rebooting over and over for some reason? |
|
|
|
你怎么知道的?垃圾。漂浮并不意味着低。
以上来自于百度翻译 以下为原文 How do you know? Rubbish. Floating does NOT mean low. |
|
|
|
回答第一个问题:(我怎么知道):当我在设置输出引脚为高之前测量电压时,所有的引脚读出大约0.133伏,但是在我设置一个引脚为高之后,所有的引脚读出3.2伏。但是,如果在设置为输出之前删除该行,则没有看到此问题,但在这种情况下,所有引脚都不作为输入。
以上来自于百度翻译 以下为原文 answer for first question:(How do i know): when i measure voltage before setting the output pin as high, all the pins read around 0.133 volts but after i set one pin as high all pins they read 3.2volts. But if I remove the line before setting as output this issue is not seen but all pins don't act as input in that case. |
|
|
|
是的,达里奥。我肯定。由于任何原因,代码不会重新启动。
以上来自于百度翻译 以下为原文 Yes Dario. i am sure. code is not rebooting over for any reasons. |
|
|
|
因为引脚是浮动的(没有驱动它们),为什么你假设它们应该读零伏特?
以上来自于百度翻译 以下为原文 Since the pins are floating (there is nothing driving them), why do you assume they should read zero volts? |
|
|
|
嗨,正如qhb所提到的,配置为Input且不与任何东西连接的管脚没有任何定义的状态。存在内部泄漏,可能导致输入处于高或低状态,正如您所观察到的,配置为Output的另一端口可能导致此改变。甚至导致输入振荡。因此,读取或使用未连接到任何东西的端口引脚的输入寄存器值是无意义的。在PIC32MX795中,有一组IO引脚可以通过使用可由CNPUE控制的弱上拉电阻器被拉到高逻辑状态对于PIC32 MX795,CNPUE控制寄存器的描述是:PIC32系列参考手册12。I/O端口“。参见大块注释1:在数据表的第12章。在其它PIC32设备中,可能同时存在弱上拉和弱下拉开关,每个端口都有单独的控制寄存器。如果输入连接到手动开关,这些内部弱上拉或弱下拉电阻器可能是有用的。他喜欢键盘或类似的东西。否则,如果逻辑信号的状态在上电或复位期间是至关重要的,或者如果某物断开,它可能被一个分立的电阻器拉到Vss或Vdd。10kOhm通常用于这个目的。
以上来自于百度翻译 以下为原文 Hi, As qhb have mentioned, a pin that is configured as Input and Not connected to anything, does NOT have any defined state. There are internal leakages that may cause the input to take a high or low state, as you have observed, another port that is configured as Output may cause this to change. Or it may even cause the input to oscillate. Thus, reading or using the Input register value for a port pin that is not connected to anything, is meaningless. In PIC32MX795 there is a subset of IO pins that may be pulled to a High logic state by use of Weak Pull Up resistors that may be controlled by: CNPUE register. For PIC32MX795 the description of CNPUE control register is in: PIC32 Family Reference Manual Section 12. "I/O Ports". See the big block Note 1: in chapter 12 of the datasheet. In other PIC32 devices there may be both Weak pull Up and Weak Pull down switches with separate control registers for each port. These internal Weak Pull Up or Weak Pull Down resistors may be useful if you have inputs connected to manual switches like a keypad or similar. Otherwise, if the state of a logic signal is critical during power up or reset, or if something is disconnected, it may be pulled down to Vss or up to Vdd by a discrete resistor. 10 kOhm will usually work for this purpose. Regards, Mysil |
|
|
|
只有小组成员才能发言,加入小组>>
5237 浏览 9 评论
2027 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3202 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
772浏览 1评论
662浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
590浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
672浏览 0评论
572浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 22:07 , Processed in 1.539560 second(s), Total 98, Slave 82 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号