完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我对微控制器和编程一般都是新手。刚拿到一个皮卡3的礼物,决定试一试。ODE编译,但微控制器不做我期望它做的事情(从1-31计数,以二进制方式输出到连接的LED)。这里的代码是:F.Prac-PracMA配置LVP= Off-PracMaMatch-CFDD=Off-Trac-Fracm配置Cp= Offy*定义X-TalthFRIQ6000空格主(空隙){TrISA=0xE0;未签名CHARI;i=0;(i=0;i & lt;=31;i++){PATA= I;γ-DelayyMS(100);如果(i=31)i=0;}
以上来自于百度翻译 以下为原文 I am new to microcontrollers and programming in general. Just got a gift of a PICKit3 and decided to test it out. The ode compiles, but the microcontroller doesn't do what I expected it to do(count from 1-31, in binary and output it to connected LEDs. Here's the code: #include #pragma config FOSC = HS #pragma config WDTE = OFF #pragma config PWRTE = OFF #pragma config MCLRE = ON #pragma config BOREN = OFF #pragma config LVP = OFF #pragma config CPD = OFF #pragma config CP = OFF #define _XTAL_FREQ 6000000 void main(void) { TRISA = 0xE0; unsigned char i; i = 0; for(i = 0; i <= 31; i++) { PORTA = i; __delay_ms(100); if(i=31)i=0; } } |
|
相关推荐
10个回答
|
|
嗨,因为我没有关于你正在使用的微控制器的信息,我只能猜测你错过了安塞尔寄存器的启动。
以上来自于百度翻译 以下为原文 Hi. As I have no info on microcontroller you are using I can only guess you are missing the ANSELx register initiation. /Sten-Åke |
|
|
|
AsSELX并不重要,当你写一个GO的整个端口。el0,这将有助于如果你透露你正在使用的PIC,如果你有一个外部晶体连接,如果你有MCLR引脚拉高。
以上来自于百度翻译 以下为原文 ANSELX does not matter when you write the whole port in one go. elZero, it would help if you revealed WHICH PIC you are using, if you have an external crystal connected, and if you have the MCLR pin pulled high. |
|
|
|
我使用PIC16F628 A。MCLR通过10K电阻被拉高。
以上来自于百度翻译 以下为原文 I am using a PIC16F628A. The MCLR is pulled high through a 10K resistor. |
|
|
|
是的,有一个外部6MHz晶体振荡器。
以上来自于百度翻译 以下为原文 And Yes, there is an external 6MHz crystal Oscillator |
|
|
|
PORTA与比较器复用,因此禁用比较器。这将有助于您阅读数据表的PATA部分。
以上来自于百度翻译 以下为原文 PORTA is multiplexed with the comparator; so disable the comparator. It would help you to read the PORTA section of your datasheet. |
|
|
|
|
|
|
|
实际上,结果是,将i设置为0,然后在循环之前的下一次递增,因此值31总是写入端口。
以上来自于百度翻译 以下为原文 You are setting i to 31 continuously with this. Actually the result is that you are setting i to 0, then it is incremented before the next time through the loop, so the value 1 is always written to the port. Regards, Dave |
|
|
|
并认为PIC RA4和RA5有点特殊,无论是只输入还是漏极。
以上来自于百度翻译 以下为原文 and also consider that on that PIC RA4 and RA5 are somewhat special, either input only or open drain |
|
|
|
有一些错误:有用的“窍门”是用“IF(31=i)”。如果意外使用“=”,则编译失败。
以上来自于百度翻译 以下为原文 There are some errors: i = 0; // Not needed while(1) { // Need an endless loop, else execution will "go into the weeds" for(i = 0; i <= 31; i++) { PORTA = i; __delay_ms(100); if(i==31) // Note the comparison operator instead of assignment i=0; } } A useful "trick" is to use "if (31==i)". If you accidentally use "=" it will fail compilation. |
|
|
|
实际的错误是一个冗余的比较内for for循环,已经照顾它…!
以上来自于百度翻译 以下为原文 actual the error is a redundant comparison inside a for loop, already taking care of it... ! |
|
|
|
只有小组成员才能发言,加入小组>>
5204 浏览 9 评论
2016 浏览 8 评论
1942 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3188 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2244 浏览 5 评论
755浏览 1评论
641浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
551浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
654浏览 0评论
554浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-5 22:25 , Processed in 1.298303 second(s), Total 66, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号